//package com.fdb.efp.limit.service.impl;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Service;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.gdrcu.lp.console.common.BizParamCfgEnum;
//import com.gdrcu.lp.console.service.api.BizParamCfgService;
//import com.gdrcu.lp.console.service.api.CoeffCfgService;
//import com.gdrcu.lp.console.service.api.PrdInfoService;
//import com.gdrcu.lp.console.service.vo.PrdInfoVO;
//import com.gdrcu.lp.console.service.vo.PrdRuleRelVO;
//import com.gdrcu.lp.ctr.service.api.CtrLoanContService;
//import com.gdrcu.lp.ctr.service.vo.CtrLoanContVO;
//import com.gdrcu.lp.cus.common.CusConstant;
//import com.gdrcu.lp.cus.service.api.CusPrelistRiskInfoService;
//import com.gdrcu.lp.cus.service.api.CusRptCdtAppService;
//import com.gdrcu.lp.cus.service.api.CusTaxBaseService;
//import com.gdrcu.lp.cus.service.vo.CusPrelistRiskInfoVO;
//import com.gdrcu.lp.cus.service.vo.CusRptCdtCardInfoVO;
//import com.gdrcu.lp.cus.service.vo.CusRptGuarInfoVO;
//import com.gdrcu.lp.cus.service.vo.CusRptLoanInfoVO;
//import com.gdrcu.lp.cus.service.vo.CusRptOverdueDetailVO;
//import com.gdrcu.lp.cus.service.vo.CusRptPromptInfoVO;
//import com.gdrcu.lp.cus.service.vo.CusRptQueryDetailVO;
//import com.gdrcu.lp.cus.service.vo.CusRptRecordVO;
//import com.gdrcu.lp.cus.service.vo.CusRptResultVO;
//import com.gdrcu.lp.framework.api.SMSService;
//import com.gdrcu.lp.framework.common.constant.BaseConstant;
//import com.gdrcu.lp.framework.common.constant.CertTypeConstant;
//import com.gdrcu.lp.framework.common.constant.CountryConstant;
//import com.gdrcu.lp.framework.common.constant.MessageScene;
//import com.gdrcu.lp.framework.common.enumeration.FlowExceptionType;
//import com.gdrcu.lp.framework.common.exception.PauseException;
//import com.gdrcu.lp.framework.common.exception.TerminateException;
//import com.gdrcu.lp.framework.common.util.DateTool;
//import com.gdrcu.lp.framework.common.util.StringUtil;
//import com.gdrcu.lp.framework.common.util.TimeUtil;
//import com.gdrcu.lp.framework.common.util.ValidationUtils;
//import com.gdrcu.lp.framework.service.FrameworkService;
//import com.gdrcu.lp.limit.common.LimitConstant;
//import com.gdrcu.lp.limit.service.api.ExecuteRuleService;
//import com.gdrcu.lp.limit.service.dao.LmtAdjustAppDao;
//import com.gdrcu.lp.limit.service.dao.LmtIndivAppDao;
//import com.gdrcu.lp.limit.service.dao.LmtPrdContDao;
//import com.gdrcu.lp.limit.service.dao.LmtPrelistDao;
//import com.gdrcu.lp.limit.service.dao.LmtShowInfoDao;
//import com.gdrcu.lp.limit.service.domain.LmtAdjustApp;
//import com.gdrcu.lp.limit.service.domain.LmtIndivApp;
//import com.gdrcu.lp.limit.service.domain.LmtPrdCont;
//import com.gdrcu.lp.limit.service.domain.LmtPrelist;
//import com.gdrcu.lp.limit.service.domain.LmtShowInfo;
//import com.gdrcu.lp.limit.service.vo.LmtPrdContVO;
//import com.gdrcu.lp.limit.service.vo.PreCreStatus;
//import com.gdrcu.lp.limit.service.vo.RunRuleResultVO;
//import com.gdrcu.lp.rule.common.constant.RuleTypeConstant;
//import com.gdrcu.lp.rule.common.enumeration.CardStatus;
//import com.gdrcu.lp.rule.common.enumeration.CreditCardType;
//import com.gdrcu.lp.rule.common.enumeration.CreditQueryType;
//import com.gdrcu.lp.rule.common.enumeration.CusLevelType;
//import com.gdrcu.lp.rule.common.enumeration.CusRelType;
//import com.gdrcu.lp.rule.common.enumeration.GuaranteeType;
//import com.gdrcu.lp.rule.common.enumeration.LoanStatus;
//import com.gdrcu.lp.rule.common.enumeration.LoanType;
//import com.gdrcu.lp.rule.common.enumeration.Nationality;
//import com.gdrcu.lp.rule.common.enumeration.RiskClassfyType;
//import com.gdrcu.lp.rule.common.enumeration.TaxPaymentEnum;
//import com.gdrcu.lp.rule.service.api.RuleCallService;
//import com.gdrcu.lp.rule.service.api.SRuleCollService;
//import com.gdrcu.lp.rule.service.vo.ApplyEntity;
//import com.gdrcu.lp.rule.service.vo.BankInnerLoanEntity;
//import com.gdrcu.lp.rule.service.vo.BizConfigParam;
//import com.gdrcu.lp.rule.service.vo.CreditCardEntity;
//import com.gdrcu.lp.rule.service.vo.CreditCardOverdueEntity;
//import com.gdrcu.lp.rule.service.vo.CreditGuarEntity;
//import com.gdrcu.lp.rule.service.vo.CreditQueryEntity;
//import com.gdrcu.lp.rule.service.vo.CreditRepaymentEntity;
//import com.gdrcu.lp.rule.service.vo.CusInfoEntity;
//import com.gdrcu.lp.rule.service.vo.CusRelInfoEntity;
//import com.gdrcu.lp.rule.service.vo.IncreaseInfoEntity;
//import com.gdrcu.lp.rule.service.vo.PayTaxUnitEntity;
//import com.gdrcu.lp.rule.service.vo.PersonalCreditEntity;
//import com.gdrcu.lp.rule.service.vo.PrdInfoEntity;
//import com.gdrcu.lp.rule.service.vo.RuleArgsEntity;
//import com.gdrcu.lp.rule.service.vo.RuleEntity;
//import com.gdrcu.lp.rule.service.vo.RuleResultEntity;
//import com.gdrcu.lp.rule.service.vo.SRuleCollVO;
//import com.gdrcu.lp.rule.service.vo.TaxBaseEntity;
//import com.gdrcu.lp.rule.service.vo.TelAprvEntity;
//import com.gdrcu.lp.xf.common.MessageType;
//import com.gdrcu.lp.xf.service.api.CusPromptMsgService;
//import com.gdrcu.lp.xf.service.api.IqpCusIndivService;
//import com.gdrcu.lp.xf.service.vo.CusPromptMsgVO;
//import com.gdrcu.lp.xf.service.vo.IqpCusIndivVO;
//
//@Service("executeRuleService")
//public class ExecuteRuleServiceImpl implements ExecuteRuleService, FrameworkService {
//    
//    private static Logger logger = LoggerFactory.getLogger(ExecuteRuleServiceImpl.class);
//    
//    @Autowired
//    private LmtPrdContDao lmtPrdContDao;
//    @Autowired
//    private LmtIndivAppDao lmtIndivAppDao;
//    @Autowired
//    private LmtPrelistDao lmtPrelistDao;
//    @Autowired
//    private LmtAdjustAppDao lmtAdjustAppDao;
//    @Autowired
//    private LmtShowInfoDao lmtShowInfoDao;
//    @Autowired
//    @Qualifier("ruleCallService")
//    private RuleCallService ruleCallService;
//    @Autowired
//    @Qualifier("cusPrelistRiskInfoService")
//    private CusPrelistRiskInfoService cusPrelistRiskInfoService;
//    @Autowired
//    @Qualifier("iqpCusIndivService")
//    private IqpCusIndivService iqpCusIndivService;//查询申请客户表信息
//    @Autowired
//    @Qualifier("cusRptCdtAppService")
//    private CusRptCdtAppService cusRptCdtAppService;//查询征信信息
//    @Autowired
//    @Qualifier("prdInfoService")
//    private PrdInfoService prdInfoService;//查询产品信息
//    @Autowired
//    @Qualifier("sRuleCollService")
//    private SRuleCollService sRuleCollService;//查询产品信息
//    
//    @Autowired
//    @Qualifier("sMSService")
//    private SMSService sMSService;
//    
//    @Autowired
//    @Qualifier("bizParamCfgService")
//    private BizParamCfgService bizParamCfgService;
//    @Autowired
//    @Qualifier("ctrLoanContService")
//    private CtrLoanContService ctrLoanContService;
//    @Autowired
//    @Qualifier("cusTaxBaseService")
//    private CusTaxBaseService cusTaxBaseService;
//
//    @Autowired
//    @Qualifier("coeffCfgService")
//    private CoeffCfgService coeffCfgService;
//    
//    @Autowired
//    @Qualifier("cusPromptMsgService")
//    private CusPromptMsgService cusPromptMsgService;
//
//    @Override
//    public RunRuleResultVO yueNongELoanAccessRule(String bizSerno) throws Exception {
//        logger.info("开始为yueNongELoanAccessRule准备数据，bizSerno=" + bizSerno);
//        RunRuleResultVO ruleResultVO = new RunRuleResultVO();
//        ruleResultVO.setBizSerno(bizSerno);//设置业务流水号
//        ruleResultVO.setIsPass(false);//先默认不通过
//        boolean reject = false;
//        String preSerno = "";
//        try {
//            /**************** 1.准备数据 start****************/
//            //查询申请数据
//            LmtIndivApp lmtIndivApp = new LmtIndivApp();
//            lmtIndivApp.setLmtSerno(bizSerno);
//            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//            if(Objects.isNull(lmtIndivApp)) {
//                throw new PauseException("未查询到授信申请信息！bizSerno=" + bizSerno);
//            }
//            preSerno = lmtIndivApp.getPreSerno();//预授信流水号
//            
//            RuleArgsEntity ruleArgsEntity = new RuleArgsEntity();
//            //获取客户信息
//            CusInfoEntity cusInfo = new CusInfoEntity();
//            //行内贷款信息
//            BankInnerLoanEntity innerLoan = new BankInnerLoanEntity();
//            //客户关联信息
//            List<CusRelInfoEntity> relInfos = new ArrayList<>();
//            
//            IqpCusIndivVO iqpCusIndivVo = new IqpCusIndivVO();
//            iqpCusIndivVo.setBizSerno(bizSerno);
//            iqpCusIndivVo = iqpCusIndivService.queryByPk(iqpCusIndivVo);
//            if (Objects.isNull(iqpCusIndivVo)) {
//                logger.error("获取客户信息失败");
//				throw new Exception("获取客户信息失败");
//			}
//            String industry = bizParamCfgService.bizParamCfgEnumFn(iqpCusIndivVo.getLegalOrgCode(),BizParamCfgEnum.FORBID_INDUS);
//            logger.info("禁入行业列表为: "+industry);
//            if (!StringUtil.isEmpty(industry)) {				
//            	String[] outIndustry = industry.split("\\,");
//            	BizConfigParam bizConfigParam = new BizConfigParam();
//            	List<String> keepOutIndustry = new ArrayList<>();
//            	for (String indInfo : outIndustry) {
//            		keepOutIndustry.add(indInfo);
//            	}
//            	logger.info("禁入行业参数为: "+JSON.toJSONString(keepOutIndustry));
//            	bizConfigParam.setKeepOutIndustry(keepOutIndustry);
//            	ruleArgsEntity.setCfgParam(bizConfigParam);//设置业务参数进入行业
//			}
//            String certCode = lmtIndivApp.getCertCode();//身份证号码
//            int age = ValidationUtils.getAgeFromIdNumber(certCode);//年龄，利用身份证号码计算
//            cusInfo.setAge(age);//年龄
//            cusInfo.setNationality(CountryConstant.CHN.equals(iqpCusIndivVo.getIndivCountry())?Nationality.CN:Nationality.OTHER);//国籍
//            if(Nationality.OTHER.equals(cusInfo.getNationality())) {
//                //判断身份证
//                cusInfo.setNationality(CertTypeConstant.CODE_10100.equals(lmtIndivApp.getCertType())?Nationality.CN:Nationality.OTHER);//国籍
//            }
//            String currWorkStartDate = iqpCusIndivVo.getIndivWorkJobY();
//            //如果为空，利用年龄减去一般大学毕业的年龄
//            if(StringUtil.isEmpty(currWorkStartDate)) {
//                String currDate = TimeUtil.getCurDate();
//                int diff = age>23 ? 23-age : 0;
//                currWorkStartDate = TimeUtil.addYear(currDate, diff);
//            } else {
//              //如果记的是年份，转换成当年的1月1日？？？？？？
//                currWorkStartDate = StringUtil.isNotEmpty(currWorkStartDate)&&currWorkStartDate.length()==4?currWorkStartDate+"-01-01":currWorkStartDate;
//            }
//            cusInfo.setCurrWorkStartDate(currWorkStartDate);//当前单位工作开始时间 yyyy-MM-dd
//            cusInfo.setIndustryType(iqpCusIndivVo.getIndivComFld());//申请人当前从事行业类型  indiv_com_fld
//            
//            CusPrelistRiskInfoVO cusPrelistRiskInfoVo = new CusPrelistRiskInfoVO();
//            cusPrelistRiskInfoVo.setPreSerno(preSerno);
//            cusPrelistRiskInfoVo = cusPrelistRiskInfoService.queryByCondition(cusPrelistRiskInfoVo);
//            if(Objects.nonNull(cusPrelistRiskInfoVo)) {
//                //申请人是否行内员工
//                cusInfo.setBankInnerStaffFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getEmployeeInd()));
//                //申请人是否黑名单
//                innerLoan.setBlackListFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getBlacklistInd()));
//                //申请人行内逾期标识
//                innerLoan.setOverdueLoanFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getLoanOdInd()));
//                //客户总授信金额 所有法人统计
//                innerLoan.setTotalCreditAmt(cusPrelistRiskInfoVo.getBankTotalLmtamt());
//                //客户单法人授信金额
//                innerLoan.setOnlyLegalCreditAmt(cusPrelistRiskInfoVo.getLegalOrgTotalLmtamt());
//                //本人是否是老赖
//                innerLoan.setDeadbeat("1".equals(cusPrelistRiskInfoVo.getDeadbeatInd())?true:false);
//                //行内未结清的机构数量
//                BigDecimal lmtLegalOrgCount = cusPrelistRiskInfoVo.getLmtLegalOrgCount();
//                lmtLegalOrgCount = lmtLegalOrgCount==null?BigDecimal.ZERO:lmtLegalOrgCount;
//                innerLoan.setNonSettleOrgNum(lmtLegalOrgCount.intValue());
//                
//                //关联人信息
//                CusRelInfoEntity cusRelInfoEntity = new CusRelInfoEntity();
//                cusRelInfoEntity.setRelType(CusRelType.SPOUSE);//配偶
//                cusRelInfoEntity.setBlackListFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getPspBlacklistInd()));//配偶是否黑名单
//                cusRelInfoEntity.setOverdueFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getPspLoanOdInd()));//配偶是否逾期
//                cusRelInfoEntity.setDeadbeat(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getPspDeadbeatInd() ));//配偶是否是老赖
//                relInfos.add(cusRelInfoEntity);
//            } else {
//                throw new PauseException("查询客户预授信名单风险信息为空！preSerno=" + lmtIndivApp.getPreSerno());
//            }
//            //最后一次被拒绝的日期，额度激活流程
//            LmtPrdCont lmtPrdCont = new LmtPrdCont();
//            lmtPrdCont.setCusId(lmtIndivApp.getCusId());
//            lmtPrdCont.setLegalOrgCode(lmtIndivApp.getLegalOrgCode());
//            LmtIndivApp lmtIndivAppCus = new LmtIndivApp();
//            lmtIndivAppCus.setCertCode(certCode);
//            String createTime = lmtIndivAppDao.getLatestRejectDate(lmtIndivAppCus);
//            createTime = StringUtil.isNotEmpty(createTime)?createTime.substring(0, 10):createTime;
//            innerLoan.setLastRefusedDate(createTime);
//            //在途的消费贷款额度激活申请
//            //TODO 消费贷款？？？
//            innerLoan.setCreditAppNum(lmtPrdContDao.queryProcessingCount(lmtPrdCont));
//            //在途的额度提额申请  TODO 有额度提额时需处理
//            innerLoan.setAddLimitAppNum(0);
//            
//            //查询产品信息
//            PrdInfoVO prdInfoVo = new PrdInfoVO();
//            prdInfoVo.setPrdId(lmtIndivApp.getPrdId());
//            prdInfoVo = prdInfoService.queryByPk(prdInfoVo);
//            if(Objects.isNull(prdInfoVo)) {
//                throw new PauseException("未查询到产品信息！prdId=" + lmtIndivApp.getPrdId());
//            }
//            
//            ApplyEntity applyEntity = new ApplyEntity();
//            if (BaseConstant.TERM_TYPE_YEAR.equals(lmtIndivApp.getTermType())) {
//            	applyEntity.setPreCreditTrem(lmtIndivApp.getApplyTerm().multiply(new BigDecimal("12")).intValue());//预授信期限				
//			}else {
//				applyEntity.setPreCreditTrem(lmtIndivApp.getApplyTerm().intValue());//预授信期限				
//			}
//            
//            PrdInfoEntity prdInfoEntity = new PrdInfoEntity();
//            if (BaseConstant.TERM_TYPE_YEAR.equals(lmtIndivApp.getTermType())) {
//            	prdInfoEntity.setCreditTerm(Integer.valueOf(prdInfoVo.getCreditTerm())*Integer.valueOf(12));//产品配置期限            	
//			}else {
//				prdInfoEntity.setCreditTerm(prdInfoVo.getCreditTerm());//产品配置期限
//			}
//            
//            applyEntity.setPrdInfo(prdInfoEntity);
//            
//            ruleArgsEntity.setCusInfo(cusInfo);
//            ruleArgsEntity.setInnerLoan(innerLoan);
//            ruleArgsEntity.setRelInfos(relInfos);
//            ruleArgsEntity.setApply(applyEntity);
//            
//            /**************** 1.准备数据 end****************/
//            //2.执行规则
//            //一般跑两次，一次省的规则，一次当前产品的规则
//            logger.info(bizSerno+"开始执行准入规则，参数："+JSON.toJSONString(ruleArgsEntity));
//            String prdId = lmtIndivApp.getPrdId();
//            
//            List<SRuleCollVO> listRuleColl = new ArrayList<>();
//            SRuleCollVO sRuleCollVo = new SRuleCollVO();
//            sRuleCollVo.setRuleCollType(RuleTypeConstant.ADMITTANCE);//准入规则
//            sRuleCollVo = sRuleCollService.queryProvinceRuleCollByType(sRuleCollVo);
//            if(Objects.nonNull(sRuleCollVo)) {
//                listRuleColl.add(sRuleCollVo);
//            } else {
//                logger.error(bizSerno+"获取省信贷准入规则为空！");
//            }
//            
//            //获取产品配置规则
//            PrdRuleRelVO prdRuleRelVO = prdInfoService.queryPrdRuleRel(prdId, RuleTypeConstant.ADMITTANCE);
//            if(Objects.nonNull(prdRuleRelVO)) {
//                SRuleCollVO sRuleCollVo2 = new SRuleCollVO();
//                sRuleCollVo2.setRuleCollId(prdRuleRelVO.getRuleCollId());
//                sRuleCollVo2.setRuleCollDesc(prdRuleRelVO.getRuleCollDesc());
//                listRuleColl.add(sRuleCollVo2);
//            } else {
//                logger.error(bizSerno+"获取产品["+prdInfoVo.getPrdCode()+"-"+prdInfoVo.getPrdName()+"]配置准入规则为空！prdId="+prdId);
//            }
//            //修改为执行完,所有配置的规则
//            if(listRuleColl.size() > 0) {
//                //所有的规则集，执行通过结果
//                List<Boolean> ruleResults = new ArrayList<>(listRuleColl.size());
//                boolean flag;
//                for(SRuleCollVO ruleCollVO : listRuleColl) {
//                    String ruleCollId = ruleCollVO.getRuleCollId();//规则集ID
//                    String ruleCollDesc = ruleCollId + "-" + ruleCollVO.getRuleCollDesc();//规则集描述
//                    RuleResultEntity ruleResultEntity = ruleCallService.executeRule(bizSerno, prdId, ruleCollId, ruleArgsEntity);
//                    if(Objects.nonNull(ruleResultEntity)) {
//                        flag = RuleEntity.PASS.equals(ruleResultEntity.getExecuteReslut());
//                        ruleResultVO.setIsPass(flag);
//                        ruleResults.add(flag);
//                        logger.info(bizSerno + "执行申请准入规则[" + ruleCollDesc + "],是否通过结果为:" + flag);
//                    }
//                }
//                for (Boolean b: ruleResults) {
//                    ruleResultVO.setIsPass(b);
//                    if(!b) {
//                        reject = true;
//                        throw new TerminateException(FlowExceptionType.FLOW, "执行申请准入规则结果为不通过,业务流程结束！bizSerno=" + bizSerno);
//                    }
//                }
//            }else {
//                //throw new PauseException("未查询到规则配置，bizSerno="+bizSerno+"，sRuleCollVo="+JSONObject.toJSONString(sRuleCollVo));
//                //未获取到规则，默认通过
//                logger.error(bizSerno+"未获取到规则配置，不执行规则！");
//            }
//        } catch (Exception e) {
//            logger.error("执行准入规则出现异常！", e);
//            throw new PauseException(e.getMessage());
//        } finally {
//            if(reject) {
//                logger.info(bizSerno+"执行准入规则结果为拒绝，更新授信申请和预授信名单状态......");
//                //更新授信申请审批状态
//                LmtIndivApp lmtIndivApp = new LmtIndivApp();
//                lmtIndivApp.setLmtSerno(bizSerno);
//                lmtIndivApp.setApproveStatus(BaseConstant.APPR_STATUS_998);
//                lmtIndivApp.setRejectReason(LimitConstant.REJECT_REASON_01);//拒绝原因
//                lmtIndivApp.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtIndivAppDao.updateByPk(lmtIndivApp);
//                
//                //更新预授信名单状态
//                LmtPrelist lmtPrelist = new LmtPrelist();
//                lmtPrelist.setPreSerno(preSerno);
//                lmtPrelist.setStatus(LimitConstant.PRELMT_STS_90);//拒绝
//                lmtPrelist.setRemarks("执行准入规则被拒绝。");
//                lmtPrelist.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtPrelistDao.updateByPk(lmtPrelist);
//                
//                //更新lmt_show_info表
//                LmtShowInfo lmtShowInfo = new LmtShowInfo();
//                lmtShowInfo.setLmtSerno(bizSerno);//授信申请流水号
//                lmtShowInfo.setLmtStatus(PreCreStatus.APPLY_FAIL.getCode());//申请失败
//                lmtShowInfo.setIncLmtInd(BaseConstant.NO);//不允许提额
//                lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后更新时间
//                lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
//                
//                //发送短信
//                logger.info(bizSerno+"授信申请准入规则拒绝，发送短信......");
//                lmtPrelist = lmtPrelistDao.queryByPk(lmtPrelist);
//                List<String> tel = new ArrayList<>();
//                tel.add(lmtPrelist.getMobile());//手机号码
//                Map<String, String> messageParam = new HashMap<>();
//                messageParam.put("NAME", lmtPrelist.getCusName());//姓名
//                messageParam.put("BRCH_NO", lmtPrelist.getLegalOrgCode());//机构号
//                sMSService.sendSms(tel, MessageScene.YUENONG_ELOAN_APPLY_REJECT.getTemplateId(), messageParam, true);
//            }
//        }
//        return ruleResultVO;
//    }
//    
//    
//    /**
//     * 风控
//     */
//    @Override
//    public RunRuleResultVO yueNongELoanRiskRule(String bizSerno) throws  Exception {
//        logger.info("开始为yueNongELoanRiskRule准备数据，bizSerno："+bizSerno);
//        RunRuleResultVO runRuleResultVO = new RunRuleResultVO();
//        runRuleResultVO.setIsPass(false);//先默认不通过
//        boolean reject = false;
//        String preSerno = "";
//        LmtPrelist lmtPrelist = null;
//        BigDecimal creditCardTotalAmt = new BigDecimal("0");//信用卡授信总额度
//        BigDecimal sixAvgUsedAmt = new BigDecimal("0");//所有的信用卡最近6个月平均使用额度
//        try {
//            //查询申请数据
//            LmtIndivApp lmtIndivApp = new LmtIndivApp();
//            lmtIndivApp.setLmtSerno(bizSerno);
//            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//            if(Objects.isNull(lmtIndivApp)) {
//                throw new PauseException("未查询到授信申请信息！bizSerno=" + bizSerno);
//            }
//            
//            preSerno = lmtIndivApp.getPreSerno();//预授信流水号
//            
//            IqpCusIndivVO iqpCusIndivVO = new IqpCusIndivVO();
//            iqpCusIndivVO.setBizSerno(bizSerno);
//            iqpCusIndivVO = iqpCusIndivService.queryByPk(iqpCusIndivVO);
//            if (Objects.isNull(iqpCusIndivVO)) {
//                throw new PauseException("查询申请客户信息为空！bizSerno=" + bizSerno);
//            }
//            lmtPrelist = new LmtPrelist();
//            lmtPrelist.setPreSerno(lmtIndivApp.getPreSerno());
//            lmtPrelist = lmtPrelistDao.queryByPk(lmtPrelist);
//            if (Objects.isNull(lmtPrelist)) {
//                throw new PauseException("查询白名单信息为空！preSerno=" + lmtIndivApp.getPreSerno());
//            }
//            //准备数据
//            RuleArgsEntity ruleArgsEntity = new RuleArgsEntity();
//            PersonalCreditEntity personalCreditEntity = new PersonalCreditEntity();//征信信息
//            
//            CusPrelistRiskInfoVO cusPrelistRiskInfoVo = new CusPrelistRiskInfoVO();
//            cusPrelistRiskInfoVo.setPreSerno(lmtIndivApp.getPreSerno());
//            cusPrelistRiskInfoVo = cusPrelistRiskInfoService.queryByCondition(cusPrelistRiskInfoVo);
//            if (Objects.isNull(cusPrelistRiskInfoVo)) {
//                throw new PauseException("查询客户预授信名单风险信息为空！preSerno=" + lmtIndivApp.getPreSerno());
//            }
//            
//            CusRptRecordVO cusRptRecordVO = new CusRptRecordVO();
//            cusRptRecordVO.setCertCode(iqpCusIndivVO.getCertCode());
//            cusRptRecordVO.setCertType(iqpCusIndivVO.getCertType());
//            cusRptRecordVO.setCusName(iqpCusIndivVO.getCusName());
//            cusRptRecordVO.setQueryMOrg(iqpCusIndivVO.getLegalOrgCode());
//            cusRptRecordVO.setBizSerno(bizSerno);
//            logger.info("查询征信信息入参:" + cusRptRecordVO);
//            CusRptResultVO cusRptResultVO = cusRptCdtAppService.queryRptResult(cusRptRecordVO);
//            if (Objects.isNull(cusRptResultVO)) {//获取查询结果对象为空				
//            	throw new PauseException("查询征信信息为空！参数：" + JSONObject.toJSONString(cusRptResultVO));
//            }else if (!cusRptResultVO.getIsAlien()) {//不是征信白户
//            	personalCreditEntity.setAlienFlag(false);
//            	if (Objects.isNull(cusRptResultVO.getCusRptCdtAppVo())||StringUtil.isEmpty(cusRptResultVO.getCusRptCdtAppVo().getReportno())) {
//            		throw new PauseException("查询征信信息为空！参数：" + JSONObject.toJSONString(cusRptResultVO));
//            	}
//			}else if (cusRptResultVO.getIsAlien()) {//征信白户
//				logger.info("征信白户! 授信流水号为: "+bizSerno);
//				personalCreditEntity.setAlienFlag(true);
//			}
//            List<CusRptCdtCardInfoVO> cardInfos = cusRptResultVO.getCusRptCdtCardInfoVo();//征信信用卡信息
//            List<CusRptLoanInfoVO> loanInfos = cusRptResultVO.getCusRptLoanInfoVo();//征信贷款信息
//            List<CusRptOverdueDetailVO> cusRptOverdueDetailVos = cusRptResultVO.getCusRptOverdueDetailVo();//逾期记录，多条记录
//            List<CusRptQueryDetailVO> cusRptQueryDetailVo = cusRptResultVO.getCusRptQueryDetailVo();//历史查询记录，多条记录
//            int cardOverDueLJ = 0; //24个月内信用卡逾期累计
//            int cardOverDueMaxLX = 0;//24个月内信用卡最大连续逾期
//            
//            
//            /***************查询征信报告次数 start***************/
//            List<CreditQueryEntity> querys = new ArrayList<>();//征信报告查询信息列表
//            if(Objects.nonNull(cusRptQueryDetailVo)) {
//                for(CusRptQueryDetailVO vo : cusRptQueryDetailVo) {
//                    CreditQueryEntity creditQueryEntity = new CreditQueryEntity();
//                    creditQueryEntity.setQueryReason(judgeQueryReason(vo.getQueryCase()));//贷款查询原因
//                    creditQueryEntity.setQueryDate(getQueryDate(vo.getQueryTime()));//查询日期 yyyy-MM-dd
//                    creditQueryEntity.setBankNo(getBankNo(vo.getQueryUser()));//卡归属银行代码/或者中文描述
//                    creditQueryEntity.setOperator(getQueryUser(vo.getQueryUser()));//操作员
//                    querys.add(creditQueryEntity);
//                }
//            }
//            personalCreditEntity.setQuerys(querys);//征信报告查询信息列表
//            /***************查询征信报告次数 end***************/
//            
//            /***************个人征信卡信息对象，含贷款/贷记卡/准贷记卡 start***************/
//            List<CreditCardEntity> cards = new ArrayList<>();
//            String regex = "\\d";//匹配数字
////            String baseDate = TimeUtil.getTimeStampByPattern(DateFormatConstant.YEAR_MONTH);//当月 yyyy-MM
////            baseDate = baseDate + "-01";//转成当月1号
//            //贷款
//            if(Objects.nonNull(loanInfos)) {
//                for(CusRptLoanInfoVO infoVO : loanInfos) {
//                	String endDate = infoVO.getRepay24stateEnd();
//                	endDate = endDate.replaceAll("\\D", "")+"01";
//                	endDate = DateTool.formatDate(endDate,DateTool.PATTERN_DEFAULT);
//                    CreditCardEntity creditCardEntity = new CreditCardEntity();
//                    creditCardEntity.setStartYearMonth(infoVO.getRepay24stateStart());//还款的开始日期
//                    creditCardEntity.setEndYearMonth(infoVO.getRepay24stateEnd());//还款的结束日期
//                    if (!StringUtil.isEmpty(infoVO.getLoanState())) {
//                    	creditCardEntity.setLoanStatus(getLoanStatus(infoVO.getLoanState()));//贷款状态						
//					}else if (!StringUtil.isEmpty(infoVO.getLoanStateDetail())) {
//						creditCardEntity.setLoanStatus(getLoanStatus(infoVO.getLoanStateDetail()));//贷款状态												
//					}else {
//						creditCardEntity.setLoanStatus(LoanStatus.OTHER);
//					}
//                    creditCardEntity.setCardNo(infoVO.getLoanId());//贷款id
//                    logger.info("贷款ID: "+creditCardEntity.getCardNo());
//                    creditCardEntity.setLoanBalAmt(infoVO.getLoanBalance());//贷款余额 
//                    creditCardEntity.setCardType(CreditCardType.LOAN_CARD);
//                    creditCardEntity.setLoanType(getLoanType(infoVO.getLoanPrd()));//贷款类型
//                    creditCardEntity.setTotalAmt(infoVO.getLoanAmount());//总额
//                    creditCardEntity.setBankNo(infoVO.getLoanOrg());//行号
//                    creditCardEntity.setRiskClassfy(getRiskClassfyType(infoVO.getFiveLevel()));//风险分类
//                    creditCardEntity.setGuarType(getGuaranteeType(infoVO.getGuarType()));//担保方式
//                    creditCardEntity.setCurrMonthUsedAmt((infoVO.getsPaymentAmt()));//当前月应还金额
//                    creditCardEntity.setLastRepayNum(infoVO.getRepaymentCyc());//剩余还款期数
//                    List<CreditCardOverdueEntity> overdueInfos = new ArrayList<>();
//                    List<CreditRepaymentEntity> repayList = new ArrayList<>();
//                    String repay_24state = infoVO.getRepay24state();//近24个月还款情况
//                    if(StringUtil.isNotEmpty(repay_24state)) {
//                        int len = repay_24state.length();
//                        for(int i=0;i<len;i++) {
//                            CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                            char c = repay_24state.charAt(len-1-i);
//                            String yearMonth = TimeUtil.addMonth(endDate, 0-i).replaceAll("-", "").substring(0, 6);//yyyyMM
//                            overdueEntity.setOverDueDate(yearMonth);//逾期月份
//                            //如果是数字
//                            if(String.valueOf(c).matches(regex)) {
//                                overdueEntity.setLastOverdueMonth(Integer.parseInt(String.valueOf(c)));//逾期持续月份
//                            } else if ('N' == c) {
//                            	CreditRepaymentEntity repaymentEntity = new CreditRepaymentEntity();
//                            	repaymentEntity.setRepayDate(yearMonth);
//                            	repayList.add(repaymentEntity);
//							}else {
//                                overdueEntity.setLastOverdueMonth(0);//逾期持续月份
//                            }
//                            overdueInfos.add(overdueEntity);
//                        }
//                    }
//                    //封装3-5年对应贷款的逾期信息
//                    if (Objects.nonNull(cusRptOverdueDetailVos)) {
//                    	for (CusRptOverdueDetailVO cusRptOverdueDetailVO : cusRptOverdueDetailVos) {
//                    		if (infoVO.getLoanId().equals(cusRptOverdueDetailVO.getLoanId())) {
//                    			CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                    			overdueEntity.setLastOverdueMonth(cusRptOverdueDetailVO.getLastOverdueMonth());
//                    			overdueEntity.setOverDueAmt(cusRptOverdueDetailVO.getOverdueAmt());
//                    			overdueEntity.setOverDueDate(cusRptOverdueDetailVO.getOverdueMonth());
//                    			overdueInfos.add(overdueEntity);
//							}     		
//                    	}			
//					}
//                    creditCardEntity.setRepayInfos(repayList);
//                    creditCardEntity.setOverdueInfos(overdueInfos);
//                    //设置当前逾期情况
//                    CreditCardOverdueEntity creditCardOverdueEntity = new CreditCardOverdueEntity();
//                    creditCardOverdueEntity.setOverDueAmt(infoVO.getCurrOverdueAmt());//当前逾期金额
//                    creditCardOverdueEntity.setLastOverdueMonth(infoVO.getCurrOverdueNum());//当前逾期期数
//                    creditCardEntity.setCurrentOver(creditCardOverdueEntity);
//                    cards.add(creditCardEntity);
//                }
//            }
//            
//            //信用卡
//            if(Objects.nonNull(cardInfos)) {
//                for(CusRptCdtCardInfoVO cardInfoVO : cardInfos) {
//                	String endDate = cardInfoVO.getRepay24stateEnd();
//                	endDate = endDate.replaceAll("\\D", "")+"01";
//                	endDate = DateTool.formatDate(endDate,DateTool.PATTERN_DEFAULT);
//                    CreditCardEntity creditCardEntity = new CreditCardEntity();
//                    creditCardEntity.setCardNo(cardInfoVO.getCardLoanId());//卡号
//                    logger.info("卡ID: "+creditCardEntity.getCardNo());
//                    creditCardEntity.setStartYearMonth(cardInfoVO.getRepay24stateStart());
//                    creditCardEntity.setEndYearMonth(cardInfoVO.getRepay24stateEnd());
//                    creditCardEntity.setCardType("1".equals(cardInfoVO.getCardType())?CreditCardType.DEBIT_CARD:CreditCardType.SEMI_CREDIT_CARD);
//                    creditCardEntity.setTotalAmt(cardInfoVO.getCardLimit());//总额
//                    creditCardEntity.setLoanBalAmt(cardInfoVO.getCardLimit().subtract(cardInfoVO.getUsedAmt()));//贷款余额 
//                    creditCardEntity.setBankNo(cardInfoVO.getCardLoanOrg());//行号
//                    if (!StringUtil.isEmpty(cardInfoVO.getCardState())) {
//                    	creditCardEntity.setCardStatus(getCardStatus(cardInfoVO.getCardState()));//卡状态						
//					}else if (!StringUtil.isEmpty(cardInfoVO.getCardStateDetail())) {
//						creditCardEntity.setCardStatus(getCardStatus(cardInfoVO.getCardStateDetail()));//卡状态												
//					}else {
//						creditCardEntity.setCardStatus(CardStatus.OTHER);
//					}
//                    creditCardEntity.setCardNo(cardInfoVO.getCardLoanId());
//                    //creditCardEntity.setCurrMonthUsedAmt(cardInfoVO.getUsedAmt());//当前月使用金额
//                    //creditCardEntity.setAvgUsedAmt(cardInfoVO.getUsedAmt());//平均使用额度
//                    List<CreditCardOverdueEntity> overdueInfos = new ArrayList<>();
//                    String repay_24state = cardInfoVO.getRepay24state();//近24个月还款情况
//                    logger.info("近24个月还款情况为: "+repay_24state);
//                    if(StringUtil.isNotEmpty(repay_24state)) {
//                        int len = repay_24state.length();
//                        for(int i=0;i<len;i++) {
//                            CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                            char c = repay_24state.charAt(len-1-i);
//                            String yearMonth = TimeUtil.addMonth(endDate, 0-i).replaceAll("-", "").substring(0, 6);//yyyyMM
//                            overdueEntity.setOverDueDate(yearMonth);//逾期月份
//                            //如果是数字
//                            if(String.valueOf(c).matches(regex)) {
//                                overdueEntity.setLastOverdueMonth(Integer.parseInt(String.valueOf(c)));//逾期持续月份
//                            } else {
//                                overdueEntity.setLastOverdueMonth(0);//逾期持续月份
//                            }
//                            overdueInfos.add(overdueEntity);
//                        }
//                    }
//                    creditCardEntity.setOverdueInfos(overdueInfos);
//                    CreditCardOverdueEntity creditCardOverdueEntity = new CreditCardOverdueEntity();
//                    creditCardOverdueEntity.setOverDueAmt(cardInfoVO.getCurrOverdueAmt());//当前逾期金额
//                    creditCardOverdueEntity.setLastOverdueMonth(cardInfoVO.getCurrOverdueNum());//当前逾期期数
//                    creditCardEntity.setCurrentOver(creditCardOverdueEntity);
//                    cards.add(creditCardEntity);//
//                    
//                    //计算卡累计逾期和连续逾期，默认最近24个月
//                    int cardOverDueMaxLXTmp = 0;
//                    String cardOverStatus = cardInfoVO.getRepay24state();
//                    char[] records = cardOverStatus.toCharArray();
//                    for (int k = 0; k < records.length; k++) {
//                        Character aa = new Character(records[k]);
//                        if (Character.isDigit(aa)) {
//                            cardOverDueLJ++;//累计
//                            cardOverDueMaxLXTmp++;
//                            if (k==records.length-1) {
//                                cardOverDueMaxLX = cardOverDueMaxLXTmp>cardOverDueMaxLX?cardOverDueMaxLXTmp:cardOverDueMaxLX;
//                                cardOverDueMaxLXTmp = 0;
//                            }
//                        }else {
//                            if (cardOverDueMaxLXTmp>cardOverDueMaxLX) {
//                                cardOverDueMaxLX = cardOverDueMaxLXTmp;
//                            }
//                            cardOverDueMaxLXTmp = 0;
//                        }
//                    }
//                }
//            }
//            CusRptPromptInfoVO cusRptPromptInfoVO = cusRptResultVO.getCusRptPromptInfoVo();//汇总信息
//            if (Objects.nonNull(cusRptPromptInfoVO)) {
//            	//组装信用卡授信总额度
//            	creditCardTotalAmt = creditCardTotalAmt.add(cusRptPromptInfoVO.getUNDLoanCardCreditLimit()).add(cusRptPromptInfoVO.getUNDSLoanCardCreditLimit());
//            	//组装所有的信用卡最近6个月平均使用额度
//            	sixAvgUsedAmt = sixAvgUsedAmt.add(cusRptPromptInfoVO.getUNDLoanCardUsedAvg6()).add(cusRptPromptInfoVO.getUNDSLoanCardUsedAvg6());
//			}
//            personalCreditEntity.setSixAvgUsedAmt(sixAvgUsedAmt);//所有的信用卡最近6个月平均使用额度
//            personalCreditEntity.setCreditCardTotalAmt(creditCardTotalAmt);//授信总额度
//            personalCreditEntity.setCards(cards);
//            personalCreditEntity.setCardDebitOverdueAllNum(cardOverDueLJ);//累计逾期
//            personalCreditEntity.setCardContiOverdueNum(cardOverDueMaxLX);//最大连续逾期
//            /***************个人征信卡信息对象，含贷款/贷记卡/准贷记卡 end***************/
//            
//            /***************特殊交易 start***************/
//            if(Objects.nonNull(cusRptPromptInfoVO)) {
//                personalCreditEntity.setLoanSpeTreansFlag(cusRptPromptInfoVO.getAssureRepayCount()>0||cusRptPromptInfoVO.getAssetDissCount()>0);
//            } else {
//                personalCreditEntity.setLoanSpeTreansFlag(false);
//            }
//            /***************特殊交易 end***************/
//            
//            /***************行内贷款信息 start***************/
//            //获取客户未结清额度
//            LmtPrdContVO lmtPrdCont = new LmtPrdContVO();
//            lmtPrdCont.setCertCode(lmtIndivApp.getCertCode());
//            lmtPrdCont.setCertType(lmtIndivApp.getCertType());
//            List<String> assureMeansList = new ArrayList<>();
//            assureMeansList.add(BaseConstant.ASSURE_MEANS_00);//信用
//            assureMeansList.add(BaseConstant.ASSURE_MEANS_30);//保证
//            lmtPrdCont.setAssureMeanList(assureMeansList);
//            //客户系统内所有机构未结清信用及保证产品的授信总金额（不含本次申请额度）不得超过N万元（N=100万）
//            BigDecimal bankTotalLmtamt = Objects.isNull(cusPrelistRiskInfoVo.getBankTotalLmtamt())?BigDecimal.ZERO:cusPrelistRiskInfoVo.getBankTotalLmtamt();
//            logger.info(bizSerno+"客户系统内所有机构未结清信用及保证产品的授信总金额为["+bankTotalLmtamt+"]，查询参数：" + JSONObject.toJSONString(lmtPrdCont));
//            
//            LmtPrdContVO lmtPrdCont2 = new LmtPrdContVO();
//            lmtPrdCont2.setCertCode(lmtIndivApp.getCertCode());
//            lmtPrdCont2.setCertType(lmtIndivApp.getCertType());
//            lmtPrdCont2.setPrdType(lmtIndivApp.getPrdType());//
//            lmtPrdCont2.setLegalOrgCode(lmtIndivApp.getLegalOrgCode());
//            //单个客户在单个法人机构的产品类型为“秒贷” 的所有额度的授信总金额≤N万元
//            BigDecimal legalOrgTotalLmtamt = lmtPrdContDao.getCusUnSettleLmtAmount(lmtPrdCont2);
//            legalOrgTotalLmtamt = Objects.isNull(legalOrgTotalLmtamt)?BigDecimal.ZERO:legalOrgTotalLmtamt;
//            logger.info(bizSerno+"单个客户在单个法人机构的产品类型为“秒贷” 的所有额度的授信总金额为["+legalOrgTotalLmtamt+"]，查询参数：" + JSONObject.toJSONString(lmtPrdCont2));
//            
//            BankInnerLoanEntity innerLoan = new BankInnerLoanEntity();
//            innerLoan.setOnlyLegalCreditAmt(legalOrgTotalLmtamt);//客户单法人授信金额(30w)
//            //BigDecimal lmtAmt = Objects.isNull(lmtPrelist.getLmtAmt())?BigDecimal.ZERO:lmtPrelist.getLmtAmt();
//            innerLoan.setTotalCreditAmt(bankTotalLmtamt);//法人机构授信总额度(100w)
//            innerLoan.setNonSettleOrgNum(cusRptPromptInfoVO==null?0:cusRptPromptInfoVO.getUNPLoanFinCorpCount());//未结清贷款法人机构数
//            /***************行内贷款信息 end***************/
//            
//            ruleArgsEntity.setCredit(personalCreditEntity);//征信信息
//            ruleArgsEntity.setInnerLoan(innerLoan);//行内贷款信息
//            
//            //执行规则
//            //一般跑两次，一次省的规则，一次产品配置的规则
//            logger.info(bizSerno+"开始执行风险规则，参数："+JSON.toJSONString(ruleArgsEntity));
//            String prdId = lmtIndivApp.getPrdId();
//            
//            List<SRuleCollVO> listRuleColl = new ArrayList<>();
//            SRuleCollVO sRuleCollVo = new SRuleCollVO();
//            sRuleCollVo.setRuleCollType(RuleTypeConstant.RISK);//准入规则
//            sRuleCollVo = sRuleCollService.queryProvinceRuleCollByType(sRuleCollVo);
//            if(Objects.nonNull(sRuleCollVo)) {
//                listRuleColl.add(sRuleCollVo);
//            } else {
//                logger.error(bizSerno+"获取省信贷风险规则为空！");
//            }
//            
//            //获取产品配置规则
//            PrdRuleRelVO prdRuleRelVO = prdInfoService.queryPrdRuleRel(prdId, RuleTypeConstant.RISK);
//            if(Objects.nonNull(prdRuleRelVO)) {
//                SRuleCollVO sRuleCollVo2 = new SRuleCollVO();
//                sRuleCollVo2.setRuleCollId(prdRuleRelVO.getRuleCollId());
//                sRuleCollVo2.setRuleCollDesc(prdRuleRelVO.getRuleCollDesc());
//                listRuleColl.add(sRuleCollVo2);
//            } else {
//                logger.error(bizSerno+"获取产品["+lmtIndivApp.getPrdCode()+"-"+lmtIndivApp.getPrdName()+"]配置风险规则为空！prdId="+prdId);
//            }
//            //修改为执行完所有配置的规则
//            if( listRuleColl.size() > 0) {
//                //所有的规则集，执行通过结果
//                List<Boolean> ruleResults = new ArrayList<>(listRuleColl.size());
//                boolean flag;
//
//                for(SRuleCollVO ruleCollVO : listRuleColl) {
//                    String ruleCollId = ruleCollVO.getRuleCollId();//规则集ID
//                    String ruleCollDesc = ruleCollId + "-" + ruleCollVO.getRuleCollDesc();//规则集描述
//                    RuleResultEntity ruleResultEntity = ruleCallService.executeRule(bizSerno, prdId, ruleCollId, ruleArgsEntity);
//                    if(Objects.nonNull(ruleResultEntity)) {
//                        flag = RuleEntity.PASS.equals(ruleResultEntity.getExecuteReslut());
//                        ruleResults.add(flag);
//                        logger.info(bizSerno + "执行风控执行规则[" + ruleCollDesc + "]是否通过结果为: " + flag);
//                    }
//                }
//                for(Boolean b : ruleResults){
//                    runRuleResultVO.setIsPass(b);
//                    if(!b) {
//                        reject = true;
//                        throw new TerminateException(FlowExceptionType.FLOW, "执行风控规则结果为不通过，业务流程结束！bizSerno=" + bizSerno);
//                    }
//                }
//            }else {
//                //throw new PauseException("未查询到规则配置，bizSerno="+bizSerno+"，sRuleCollVo="+JSONObject.toJSONString(sRuleCollVo));
//                //未获取到规则配置，允许通过
//                logger.error(bizSerno+"未获取到规则配置，不执行规则！");
//            }
//            
//        } catch (Exception e) {
//            logger.error("执行风险规则出现异常！", e);
//            throw new PauseException(e.getMessage());
//        } finally {
//            if(reject) {
//                logger.info(bizSerno+"执行风险规则结果为拒绝，更新授信申请和预授信名单状态......");
//                //更新授信申请审批状态
//                LmtIndivApp lmtIndivApp = new LmtIndivApp();
//                lmtIndivApp.setLmtSerno(bizSerno);
//                lmtIndivApp.setApproveStatus(BaseConstant.APPR_STATUS_998);
//                lmtIndivApp.setRejectReason(LimitConstant.REJECT_REASON_02);//拒绝原因
//                lmtIndivApp.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtIndivAppDao.updateByPk(lmtIndivApp);
//                
//                //更新预授信名单状态
//                LmtPrelist lmtPrelist2 = new LmtPrelist();
//                lmtPrelist2.setPreSerno(preSerno);
//                lmtPrelist2.setStatus(LimitConstant.PRELMT_STS_90);//拒绝
//                lmtPrelist2.setRemarks("执行风险规则被拒绝。");
//                lmtPrelist2.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtPrelistDao.updateByPk(lmtPrelist2);
//                
//                //更新lmt_show_info表
//                LmtShowInfo lmtShowInfo = new LmtShowInfo();
//                lmtShowInfo.setLmtSerno(bizSerno);//授信申请流水号
//                lmtShowInfo.setLmtStatus(PreCreStatus.APPLY_FAIL.getCode());//申请失败
//                lmtShowInfo.setIncLmtInd(BaseConstant.NO);//不允许提额
//                lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后更新时间
//                lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
//                
//                //发送短信
//                logger.info(bizSerno+"授信申请风险规则拒绝，发送短信......");
//                List<String> tel = new ArrayList<>();
//                tel.add(lmtPrelist.getMobile());//手机号码
//                Map<String, String> messageParam = new HashMap<>();
//                messageParam.put("NAME", lmtPrelist.getCusName());//姓名
//                messageParam.put("BRCH_NO", lmtPrelist.getLegalOrgCode());//机构号
//                sMSService.sendSms(tel, MessageScene.YUENONG_ELOAN_APPLY_REJECT.getTemplateId(), messageParam, true);
//            }
//        }
//        return runRuleResultVO;
//    }
//
//     /**
//      * 额度测算
//      */
//    @Override
//    public BigDecimal yueNongELoanCalcLimit(String bizSerno) throws Exception {
//        logger.info("开始为yueNongELoanCalcLimit准备数据，bizSerno"+bizSerno);
//        BigDecimal resultAmt = BigDecimal.ZERO;//默认额度
//        RunRuleResultVO runRuleResultVO = new RunRuleResultVO();
//        runRuleResultVO.setUltLimit(BigDecimal.ZERO);//先默认是0
//        LmtIndivApp lmtIndivApp = null;
//        LmtPrelist lmtPrelist = null;
//        boolean reject = false;
//        String message = "";
//        try {
//            //查询申请数据
//            lmtIndivApp = new LmtIndivApp();
//            lmtIndivApp.setLmtSerno(bizSerno);
//            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//            if(Objects.isNull(lmtIndivApp)) {
//                throw new PauseException("未查询到授信申请信息！bizSerno=" + bizSerno);
//            }
//            //额度测算
//            lmtPrelist = new LmtPrelist();
//            lmtPrelist.setPreSerno(lmtIndivApp.getPreSerno());
//            lmtPrelist = lmtPrelistDao.queryByPk(lmtPrelist);
//            if (Objects.isNull(lmtPrelist)) {
//                throw new PauseException("查询白名单信息为空！preSerno=" + lmtIndivApp.getPreSerno());
//            }
//            IqpCusIndivVO iqpCusIndivVO = new IqpCusIndivVO();
//            iqpCusIndivVO.setBizSerno(bizSerno);
//            logger.info("当前查询信息为: "+JSON.toJSONString(iqpCusIndivVO));
//            iqpCusIndivVO = iqpCusIndivService.queryByPk(iqpCusIndivVO);
//            if (Objects.isNull(iqpCusIndivVO)) {
//                logger.error("查询申请客户信息为空",new RuntimeException("查询申请客户信息为空"));
//                return null;
//            }
//            String prdId = lmtIndivApp.getPrdId();
//            PrdInfoVO prdInfoVO = new PrdInfoVO();
//            prdInfoVO.setPrdId(prdId);
//            prdInfoVO = prdInfoService.queryByPk(prdInfoVO);
//            if (Objects.isNull(prdInfoVO)) {
//                throw new PauseException("查询产品信息为空！prdId=" + lmtIndivApp.getPrdId());
//            }
//            
//            CusPrelistRiskInfoVO cusPrelistRiskInfoVo = new CusPrelistRiskInfoVO();
//            cusPrelistRiskInfoVo.setPreSerno(lmtIndivApp.getPreSerno());
//            cusPrelistRiskInfoVo = cusPrelistRiskInfoService.queryByCondition(cusPrelistRiskInfoVo);
//            if (Objects.isNull(cusPrelistRiskInfoVo)) {
//                throw new PauseException("查询客户预授信名单风险信息为空！preSerno=" + lmtIndivApp.getPreSerno());
//            }
//            
//            CusRptRecordVO cusRptRecordVO = new CusRptRecordVO();
//            cusRptRecordVO.setCertCode(lmtIndivApp.getCertCode());
//            cusRptRecordVO.setCertType(lmtIndivApp.getCertType());
//            cusRptRecordVO.setCusName(lmtIndivApp.getCusName());
//            cusRptRecordVO.setQueryMOrg(lmtIndivApp.getLegalOrgCode());
//            cusRptRecordVO.setBizSerno(bizSerno);
//            CusRptResultVO cusRptResultVO = cusRptCdtAppService.queryRptResult(cusRptRecordVO);
//            if (Objects.isNull(cusRptResultVO)) {				
//            	throw new PauseException("查询征信信息为空！参数：" + JSONObject.toJSONString(cusRptResultVO));
//            }else if (!cusRptResultVO.getIsAlien()) {
//            	if (Objects.isNull(cusRptResultVO.getCusRptCdtAppVo())||StringUtil.isEmpty(cusRptResultVO.getCusRptCdtAppVo().getReportno())) {
//            		throw new PauseException("查询征信信息为空！参数：" + JSONObject.toJSONString(cusRptResultVO));
//            	}
//			}else if (cusRptResultVO.getIsAlien()) {
//				logger.info("征信白户! 授信流水号为: "+bizSerno);
//			}
//            List<CusRptCdtCardInfoVO> cardInfos = cusRptResultVO.getCusRptCdtCardInfoVo();//征信信用卡信息
//            List<CusRptLoanInfoVO> loanInfos = cusRptResultVO.getCusRptLoanInfoVo();//征信贷款信息
//            List<CusRptOverdueDetailVO> cusRptOverdueDetailVos = cusRptResultVO.getCusRptOverdueDetailVo();//逾期记录，多条记录
//            List<CusRptGuarInfoVO> cusRptGuarInfoVo = cusRptResultVO.getCusRptGuarInfoVo();//担保信息列表
//            /**************** 1.准备数据 start****************/
//            RuleArgsEntity ruleArgsEntity = new RuleArgsEntity();
//            String regex = "\\d";//匹配数字
//            //客户信息CusInfoEntity cusInfo;
//            CusInfoEntity cusInfo = new CusInfoEntity();
//            cusInfo.setAge(ValidationUtils.getAgeFromIdNumber(iqpCusIndivVO.getCertCode()));
//            cusInfo.setCusId(iqpCusIndivVO.getCusId());
//            cusInfo.setCusName(iqpCusIndivVO.getCusName());
//            cusInfo.setIdType(iqpCusIndivVO.getCertType());
//            cusInfo.setIdCard(iqpCusIndivVO.getCertCode());
//            cusInfo.setIndustryType(iqpCusIndivVO.getIndivComFld());
//            String cusLevel = lmtPrelist.getCusLevel();
//            if (!StringUtil.isEmpty(cusLevel)) {		
//            	switch (cusLevel) {
//            	case CusConstant.CUS_LEVEL_A:
//            		cusInfo.setCuLevel(CusLevelType.PUBLIC);
//            		break;
//            	case CusConstant.CUS_LEVEL_B:
//            		cusInfo.setCuLevel(CusLevelType.FINANCIAL);
//            		break;
//            	case CusConstant.CUS_LEVEL_C:
//            		cusInfo.setCuLevel(CusLevelType.VIP);
//            		break;
//            	case CusConstant.CUS_LEVEL_D:
//            		cusInfo.setCuLevel(CusLevelType.WEALTH);
//            		break;
//            	case CusConstant.CUS_LEVEL_E:
//            		cusInfo.setCuLevel(CusLevelType.PRIVATE_BANK);
//            		break;
//            	}
//			}
//            cusInfo.setBankInnerStaffFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getEmployeeInd()));
//            //cusInfo.setCuLevel(cuLevel);
//            cusInfo.setNationality(CountryConstant.CHN.equals(iqpCusIndivVO.getIndivCountry())?Nationality.CN:Nationality.OTHER);//国际
//            //客户关联信息List<CusRelInfoEntity> relInfos;
//            List<CusRelInfoEntity> relInfos = new ArrayList<>();
//            CusRelInfoEntity relInfoEntity = new CusRelInfoEntity();
//            relInfoEntity.setRelType(CusRelType.SPOUSE);//配偶
//            relInfoEntity.setBlackListFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getPspBlacklistInd()));//配偶是否黑名单
//            relInfoEntity.setOverdueFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getPspLoanOdInd()));//配偶是否逾期
//            relInfos.add(relInfoEntity);
//            //行内贷款信息BankInnerLoanEntity innerLoan;
//            BankInnerLoanEntity innerLoan  = new BankInnerLoanEntity();
//            innerLoan.setBlackListFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getBlacklistInd()));
//            innerLoan.setOverdueLoanFlag(BaseConstant.YES.equals(cusPrelistRiskInfoVo.getLoanOdInd()));
//            innerLoan.setOnlyLegalCreditAmt(cusPrelistRiskInfoVo.getLegalOrgTotalLmtamt());//客户单法人授信金额
//            innerLoan.setTotalCreditAmt(cusPrelistRiskInfoVo.getBankTotalLmtamt());//法人机构授信总额度
//            //客户系统内（指得是行内系统贷款）所有机构未结清信用及保证产品的授信总金额（含本次申请额度）不得超过N万元（N=100万）
//            innerLoan.setTotalCreditGuarAmt(cusPrelistRiskInfoVo.getBankTotalLmtamt());
//
//            //征信信息PersonalCreditEntity credit;
//            PersonalCreditEntity credit = new PersonalCreditEntity();
//            //担保信息
//            List<CreditGuarEntity> guars = new ArrayList<>();
//            if (Objects.nonNull(cusRptGuarInfoVo)&&cusRptGuarInfoVo.size()>0) {				
//            for (CusRptGuarInfoVO guarInfoVO : cusRptGuarInfoVo) {
//            	CreditGuarEntity entity = new CreditGuarEntity();
//            	entity.setGuarAmt(guarInfoVO.getGuarAmt());//担保金额
//            	entity.setGuarBalAmt(guarInfoVO.getGuarLoanBln());//担保贷款余额
//            	entity.setGuarStartDate(guarInfoVO.getGuarLoanStartDate());
//            	entity.setGuarEndDate(guarInfoVO.getGuarLoanEndDate());
//            	entity.setGuarLoanOrg(guarInfoVO.getGuarLoanOrg());
//            	entity.setPayDate(guarInfoVO.getPayDate());
//            	guars.add(entity);
//			}
//            }
//            List<CreditCardEntity> cards = new ArrayList<>();
//            //信用卡 
//            if (Objects.nonNull(cardInfos)&&cardInfos.size()>0) {				
//            for (CusRptCdtCardInfoVO cardInfoVO : cardInfos) {
//                String endDate = cardInfoVO.getRepay24stateEnd();
//            	endDate = endDate.replaceAll("\\D", "")+"01";
//            	endDate = DateTool.formatDate(endDate,DateTool.PATTERN_DEFAULT);
//                CreditCardEntity creditCard = new CreditCardEntity();
//                creditCard.setCardType("1".equals(cardInfoVO.getCardType())?CreditCardType.DEBIT_CARD:CreditCardType.SEMI_CREDIT_CARD);//卡类型
//                if (!StringUtil.isEmpty(cardInfoVO.getCardState())) {
//                	creditCard.setCardStatus(getCardStatus(cardInfoVO.getCardState()));//卡状态						
//				}else if (!StringUtil.isEmpty(cardInfoVO.getCardStateDetail())) {
//					creditCard.setCardStatus(getCardStatus(cardInfoVO.getCardStateDetail()));//卡状态												
//				}else {
//					creditCard.setCardStatus(CardStatus.OTHER);
//				}
//                //creditCard.setLoanBalAmt(loanBalAmt);//贷款余额
//                creditCard.setCurrMonthUsedAmt(cardInfoVO.getUsedAmt());//当前月使用金额
//                creditCard.setAvgUsedAmt(cardInfoVO.getUsedAmt());//平均使用额度
//                //creditCard.setGuarType(guarType);//担保方式
//                //creditCard.setLastRepayNum(lastRepayNum);//剩余还款期数
//                //creditCard.setTrem(trem);
//                creditCard.setBankNo(cardInfoVO.getCardLoanOrg());
//                creditCard.setCardNo(cardInfoVO.getCardLoanId());
//                creditCard.setTotalAmt(cardInfoVO.getCardLimit());
//                List<CreditCardOverdueEntity> overdueInfos = new ArrayList<>();
//                String repay_24state = cardInfoVO.getRepay24state();//近24个月还款情况
//                logger.info("近24个月还款情况为: "+repay_24state);
//                if(StringUtil.isNotEmpty(repay_24state)) {
//                    int len = repay_24state.length();
//                    for(int i=0;i<len;i++) {
//                        CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                        char c = repay_24state.charAt(len-1-i);
//                        String yearMonth = TimeUtil.addMonth(endDate, 0-i).replaceAll("-", "").substring(0, 6);//yyyyMM
//                        overdueEntity.setOverDueDate(yearMonth);//逾期月份
//                        //如果是数字
//                        if(String.valueOf(c).matches(regex)) {
//                            overdueEntity.setLastOverdueMonth(Integer.parseInt(String.valueOf(c)));//逾期持续月份
//                        } else {
//                            overdueEntity.setLastOverdueMonth(0);//逾期持续月份
//                        }
//                        overdueInfos.add(overdueEntity);
//                    }
//                }
//                creditCard.setOverdueInfos(overdueInfos);
//                
//                
//                cards.add(creditCard);
//            }
//            }         
//            if (Objects.nonNull(loanInfos) && loanInfos.size()>0) {
//            //贷款
//            for (CusRptLoanInfoVO infoVO : loanInfos) {
//                String endDate = infoVO.getRepay24stateEnd();
//            	endDate = endDate.replaceAll("\\D", "")+"01";
//            	endDate = DateTool.formatDate(endDate,DateTool.PATTERN_DEFAULT);
//                CreditCardEntity creditCard = new CreditCardEntity();
//                creditCard.setCardType(CreditCardType.LOAN_CARD);//卡类型
//                creditCard.setTotalAmt(infoVO.getLoanAmount());//贷款总金额
//                creditCard.setLoanBalAmt(infoVO.getLoanBalance());//贷款余额
//                creditCard.setCurrMonthUsedAmt(infoVO.getsPaymentAmt());//当前月应还金额
//                //creditCard.setAvgUsedAmt(cusRptCdtCardInfoVO.getUsedAmt());//平均使用额度
//                String guarType = infoVO.getGuarType();
//                creditCard.setGuarType(getGuaranteeType(guarType));//担保方式 其他
//                creditCard.setLastRepayNum(infoVO.getRepaymentCyc());//剩余还款期数
//                //creditCard.setTrem(trem);
//                creditCard.setBankNo(infoVO.getLoanOrg());//银行机构号
//                if (!StringUtil.isEmpty(infoVO.getLoanState())) {
//                	creditCard.setLoanStatus(getLoanStatus(infoVO.getLoanState()));//贷款状态						
//                }else if (!StringUtil.isEmpty(infoVO.getLoanStateDetail())) {
//                	creditCard.setLoanStatus(getLoanStatus(infoVO.getLoanStateDetail()));//贷款状态												
//                }else {
//                	creditCard.setLoanStatus(LoanStatus.OTHER);
//                }
//                //creditCard.setCardNo(cusRptCdtCardInfoVO.getCardLoanId());
//                creditCard.setLoanType(LoanType.BUSINESS);//贷款类型待定 需要确认征信字段
//                String riskClassfy = infoVO.getFiveLevel();
//                switch (riskClassfy) {
//                case "关注":
//                    creditCard.setRiskClassfy(RiskClassfyType.FOCUS_ONE);
//                    break;
//                case "正常":
//                    creditCard.setRiskClassfy(RiskClassfyType.NORMAL_ONE);
//                    break;
//                case "可疑":
//                    creditCard.setRiskClassfy(RiskClassfyType.SUSPICIOUS);
//                    break;
//                case "次级":
//                    creditCard.setRiskClassfy(RiskClassfyType.SECONDARY);
//                    break;
//                case "损失":
//                    creditCard.setRiskClassfy(RiskClassfyType.LOSS);
//                    break;
//                }             
//                List<CreditCardOverdueEntity> overdueInfos = new ArrayList<>();
//                String repay_24state = infoVO.getRepay24state();//近24个月还款情况
//                if(StringUtil.isNotEmpty(repay_24state)) {
//                    int len = repay_24state.length();
//                    for(int i=0;i<len;i++) {
//                        CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                        char c = repay_24state.charAt(len-1-i);
//                        String yearMonth = TimeUtil.addMonth(endDate, 0-i).replaceAll("-", "").substring(0, 6);//yyyyMM
//                        overdueEntity.setOverDueDate(yearMonth);//逾期月份
//                        //如果是数字
//                        if(String.valueOf(c).matches(regex)) {
//                            overdueEntity.setLastOverdueMonth(Integer.parseInt(String.valueOf(c)));//逾期持续月份
//                        } else {
//                            overdueEntity.setLastOverdueMonth(0);//逾期持续月份
//                        }
//                        overdueInfos.add(overdueEntity);
//                    }
//                }
//                //封装3-5年对应贷款的逾期信息
//                if (Objects.nonNull(cusRptOverdueDetailVos)) {
//                	for (CusRptOverdueDetailVO cusRptOverdueDetailVO : cusRptOverdueDetailVos) {
//                		if (infoVO.getLoanId().equals(cusRptOverdueDetailVO.getLoanId())) {
//                			CreditCardOverdueEntity overdueEntity = new CreditCardOverdueEntity();
//                			overdueEntity.setLastOverdueMonth(cusRptOverdueDetailVO.getLastOverdueMonth());
//                			overdueEntity.setOverDueAmt(cusRptOverdueDetailVO.getOverdueAmt());
//                			overdueEntity.setOverDueDate(cusRptOverdueDetailVO.getOverdueMonth());
//                			overdueInfos.add(overdueEntity);
//						}     		
//                	}			
//				}
//                creditCard.setOverdueInfos(overdueInfos);                
//                cards.add(creditCard);
//            }
//            }
//            CusRptPromptInfoVO promptInfoVO = cusRptResultVO.getCusRptPromptInfoVo();//汇总信息
//            List<CreditQueryEntity> querys = new ArrayList<>();//不传
//            logger.info("征信信用信息为: "+JSON.toJSONString(promptInfoVO));
//            BigDecimal LoanCardUsedAvg6 = promptInfoVO==null?null:promptInfoVO.getUNDLoanCardUsedAvg6();
//            BigDecimal sLoanCardUsedAvg6 = promptInfoVO==null?null:promptInfoVO.getUNDSLoanCardUsedAvg6();
//            LoanCardUsedAvg6 = LoanCardUsedAvg6==null?BigDecimal.ZERO:LoanCardUsedAvg6;
//            logger.info("最近6个月平均额度: "+JSON.toJSONString(LoanCardUsedAvg6));
//            sLoanCardUsedAvg6 = sLoanCardUsedAvg6==null?BigDecimal.ZERO:sLoanCardUsedAvg6;
//            logger.info("未结清6个月平均额度: "+JSON.toJSONString(sLoanCardUsedAvg6));
//            BigDecimal userAvg6 = LoanCardUsedAvg6.add(sLoanCardUsedAvg6);
//            credit.setSixAvgUsedAmt(userAvg6);//最近6个月平均使用额度
//            logger.info("征信相关信息为: "+JSON.toJSONString(cards));
//            credit.setCards(cards);
//            credit.setQuerys(querys);
//            credit.setGuars(guars);
//            //credit.setDebitCardUsedAmt(cusRptPromptInfoVO.getUNDLoanCardUsedCredit());//
//            if (Objects.nonNull(promptInfoVO)) {				
//            	credit.setTotalGuarBalAmt(promptInfoVO.getGuarBalance());
//            	BigDecimal loanUsedLimit = Objects.isNull(promptInfoVO.getUNDLoanCardUsedCredit())?BigDecimal.ZERO:promptInfoVO.getUNDLoanCardUsedCredit();
//            	BigDecimal sloanUseLimit = Objects.isNull(promptInfoVO.getUNDSLoanCardUsedCredit())?BigDecimal.ZERO:promptInfoVO.getUNDSLoanCardUsedCredit();   
//            	credit.setCreditCardUsedTotalAmt(loanUsedLimit.add(sloanUseLimit));//所有信用卡已用额度
//			}
//            //申请相关信息ApplyEntity apply;
//            ApplyEntity apply = new ApplyEntity();
//            apply.setPreCreditTrem(lmtPrelist.getTerm().intValue());//预授信期限
//            apply.setPreCreditAmt(lmtPrelist.getLmtAmt());//白名单导入预授信额度
//            //applyEntity.setMarketAmt("");//营销额度
//            apply.setMaxPreCreditAmt(lmtPrelist.getMaxCreditLimit());//白名单最高授信额度
//            apply.setProLimit(lmtPrelist.getProLimit()); //省级限额
//            PrdInfoEntity prdInfoEntity = new PrdInfoEntity();
//            prdInfoEntity = (PrdInfoEntity)beanCopy(prdInfoVO, prdInfoEntity);
//            apply.setPrdInfo(prdInfoEntity);
//            //电核TelAprvEntity telAprv;
//            TelAprvEntity telAprv = new TelAprvEntity();
//            //业务参数配置信息BizConfigParam cfgParam;
//            BizConfigParam cfgParam = new BizConfigParam();
//            //省级业务参数配置 授信总限额（万）
//            String crdLmtAmtStr = bizParamCfgService.bizParamCfgEnumFn("00001", BizParamCfgEnum.CRD_LMT_AMT);
//            BigDecimal crdLmtAmt = null;
//            if ( !StringUtils.isEmpty(crdLmtAmtStr) )
//                crdLmtAmt = new BigDecimal(crdLmtAmtStr);
//            //法人机构业务参数配置 授信总限额（万）
//            String legalCrdLmtAmtStr = bizParamCfgService.bizParamCfgEnumFn(iqpCusIndivVO.getLegalOrgCode(), BizParamCfgEnum.CRD_LMT_AMT);;
//            BigDecimal legalCrdLmtAmt = null;
//            if ( !StringUtils.isEmpty(legalCrdLmtAmtStr) )
//                legalCrdLmtAmt = new BigDecimal(legalCrdLmtAmtStr);
//            if ( crdLmtAmt == null && legalCrdLmtAmt != null ) {
//                crdLmtAmt = legalCrdLmtAmt;
//            }else if ( crdLmtAmt != null && legalCrdLmtAmt != null) {
//                crdLmtAmt = crdLmtAmt.min(legalCrdLmtAmt);
//            }
//            cfgParam.setCrdLmtAmt(crdLmtAmt);
//            ruleArgsEntity.setCusInfo(cusInfo);
//            ruleArgsEntity.setRelInfos(relInfos);
//            ruleArgsEntity.setInnerLoan(innerLoan);
//            ruleArgsEntity.setCredit(credit);
//            ruleArgsEntity.setApply(apply);
//            ruleArgsEntity.setTelAprv(telAprv);
//            ruleArgsEntity.setCfgParam(cfgParam);
//            /**************** 1.准备数据 end****************/
//            logger.info("开始调用额度测算规则，参数为: "+JSON.toJSONString(ruleArgsEntity));
//            String ruleCollId = prdInfoVO.getCrdMeaMedolId();//额度测算模型ID
//            if(StringUtil.isEmpty(ruleCollId)) {
//                throw new PauseException("未配置额度测算模型，请检查产品配置！bizSerno=" + bizSerno+"，prdId="+prdId);
//            }
//            
//            resultAmt = ruleCallService.calcLimit(bizSerno, prdId, ruleCollId, ruleArgsEntity);
//            resultAmt = resultAmt==null?BigDecimal.ZERO:resultAmt;
//            
//            logger.info(bizSerno+"最后计算额度为: "+resultAmt);
//            
//            //与产品最大最小额度比较
//            //最终额度=min(测算额度, 产品最大金额) 或者  最终额度=min(测算额度, 产品最小金额)
//            BigDecimal prdMax = prdInfoVO.getCrdAprvMaxAmt();
//            BigDecimal prdMin = prdInfoVO.getCrdAprvMinAmt();
//            resultAmt = resultAmt.compareTo(prdMax)==1?prdMax:resultAmt;
//            reject = prdMin.compareTo(resultAmt)==1;//测算额度比产品最小金额小，拒绝
//            
//            if(reject) {
//                message = "测算额度["+resultAmt+"]小于产品最小额度["+prdMin+"]，拒绝。";
//                throw new TerminateException(FlowExceptionType.EVENT, message+"业务流程结束！");
//            }
//            
//            LmtIndivApp lmtIndivApp2 = new LmtIndivApp();
//            lmtIndivApp2.setLmtSerno(bizSerno);
//            lmtIndivApp2.setApproveAmt(resultAmt);
//            lmtIndivApp2.setApplyAmt(resultAmt);
//            lmtIndivApp2.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//            int count = lmtIndivAppDao.updateByPk(lmtIndivApp2);
//            logger.info("回写额度到授信申请表：" + (count==1?"success":"failure"));
//            
//        } catch (Exception e) {
//            logger.error("额度测算出现异常！", e);
//            throw new PauseException(e.getMessage());
//        } finally {
//            if(reject) {
//                //回写额度
//                LmtIndivApp lmtIndivApp2 = new LmtIndivApp();
//                lmtIndivApp2.setLmtSerno(bizSerno);
//                lmtIndivApp2.setApproveAmt(resultAmt);
//                lmtIndivApp2.setApplyAmt(resultAmt);
//                lmtIndivApp2.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtIndivApp2.setApproveStatus(BaseConstant.APPR_STATUS_998);
//                lmtIndivApp2.setRejectReason(LimitConstant.REJECT_REASON_03);//拒绝原因
//                int count = lmtIndivAppDao.updateByPk(lmtIndivApp2);
//                logger.info("回写额度到授信申请表：" + (count==1?"success":"failure"));
//                
//                //更新预授信名单状态
//                LmtPrelist lmtPrelist2 = new LmtPrelist();
//                lmtPrelist2.setPreSerno(lmtIndivApp.getPreSerno());
//                lmtPrelist2.setStatus(LimitConstant.PRELMT_STS_90);//拒绝
//                lmtPrelist2.setRemarks(message);
//                lmtPrelist2.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                lmtPrelistDao.updateByPk(lmtPrelist2);
//                
//                //更新lmt_show_info表
//                LmtShowInfo lmtShowInfo = new LmtShowInfo();
//                lmtShowInfo.setLmtSerno(bizSerno);//授信申请流水号
//                lmtShowInfo.setLmtStatus(PreCreStatus.APPLY_FAIL.getCode());//申请失败
//                //lmtShowInfo.setLmtType(LimitConstant.PRELMT_TYPE_1);//修改预授信额度类型：预授信额度
//                lmtShowInfo.setLmtAmt(BigDecimal.ZERO);//授信额度
//                lmtShowInfo.setIncLmtInd(BaseConstant.YES);//额度过低，允许提额
//                lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后更新时间
//                lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
//                
//                //发送短信
//                logger.info(bizSerno+message+"发送短信......");
//                List<String> tel = new ArrayList<>();
//                tel.add(lmtPrelist.getMobile());//手机号码
//                Map<String, String> messageParam = new HashMap<>();
//                messageParam.put("NAME", lmtPrelist.getCusName());//姓名
//                messageParam.put("BRCH_NO", lmtPrelist.getLegalOrgCode());//机构号
//                sMSService.sendSms(tel, MessageScene.YUENONG_ELOAN_APPLY_REJECT.getTemplateId(), messageParam, true);
//            }
//        }
//        return resultAmt;
//    }
//      
//    /**
//     * 判断查询类型
//     * @param queryCase
//     * @return
//     */
//    private CreditQueryType judgeQueryReason(String queryCase) {
//        String qCase = queryCase==null?"":queryCase.trim();
//        switch(qCase) {
//        case "贷款审批" :
//            return CreditQueryType.LOAN_APPR;
//        case "信用卡审批" :
//            return CreditQueryType.CREDIT_CARD_APPR;
//        case "贷后管理" :
//            return CreditQueryType.LOAN_AFTER_MANAGE;
//        default:
//            return CreditQueryType.OTHER;
//        }
//    }
//    
//    /**
//     * 获取查询日期，转换为 yyyy-MM-dd
//     * @param queryDate
//     * @return
//     */
//    private String getQueryDate(String queryDate) {
//        if(StringUtil.isEmpty(queryDate)) {
//            return "";
//        }
//        String date = queryDate.replaceAll("\\D", "");//替换所有非数字字符
//        date = date.substring(0, 8);
//        date = date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
//        return date;
//    }
//    
//    /**
//     * 获取行号
//     * @param queryUser
//     * @return
//     */
//    private String getBankNo(String queryUser) {
//        if(StringUtil.isEmpty(queryUser)) {
//            return "";
//        }
//        String[] arr = queryUser.split("/");
//        return arr[0];
//    }
//    
//    /**
//     * 获取行号
//     * @param queryUser
//     * @return
//     */
//    private String getQueryUser(String queryUser) {
//        if(StringUtil.isEmpty(queryUser)) {
//            return "";
//        }
//        String[] arr = queryUser.split("/");
//        return arr.length==2?arr[1]:arr[0];
//    }
//    
//    /**
//     * 获取贷款类型
//     * @param loanPrd
//     * @return
//     */
//    private LoanType getLoanType(String loanPrd) {
//        String type = loanPrd==null?"":loanPrd.trim();
//        if(type.indexOf("个人消费贷款")!=-1||type.indexOf("消费贷款")!=-1) {
//            return LoanType.CONSUME;
//        } else if(type.indexOf("个人经营性贷款")!=-1||type.indexOf("经营性贷款")!=-1) {
//            return LoanType.OPERATE;
//        } else if(type.indexOf("个人住房贷款")!=-1||type.indexOf("住房贷款")!=-1
//                ||type.indexOf("个人住房公积金贷款")!=-1||type.indexOf("住房公积金贷款")!=-1
//                ||type.indexOf("个人商用房（包括商住两用）贷款")!=-1||type.indexOf("商用房（包括商住两用）贷款")!=-1) {
//            return LoanType.HOUSE;
//        } else {
//            return LoanType.OTHER;
//        }
//    }
//    
//    /**
//     * 获取卡状态
//     * @param cardStatus
//     * @return
//     */
//    private CardStatus getCardStatus(String cardStatus) {
//        String status = cardStatus==null?"":cardStatus.trim();
//        switch(status) {
//        case "正常":
//            return CardStatus.NORMAL;
//        case "逾期":
//            return CardStatus.OVERDUE;
//        case "呆账":
//            return CardStatus.BAD_DEBT;
//        case "冻结":
//            return CardStatus.FROZEN;
//        case "止付":
//            return CardStatus.STOP_PAYMENT;
//        case "结清":
//            return CardStatus.SETTLE;
//        case "异常":
//            return CardStatus.EXCEPTION;
//        case "挂失":
//            return CardStatus.REPORT_LOSE;
//        case "销户":
//        	return CardStatus.CACEL_ACCOUNT;
//        case "核销":
//        	return CardStatus.CANCEL_AFTER_VERIFI;
//        case "未激活":
//        	return CardStatus.NO_ACTIVATION;
//        default :
//            return CardStatus.OTHER;
//        }
//    }
//    
//    /**
//     * 获取风险分类
//     * @param fiveLevel
//     * @return
//     */
//    private RiskClassfyType getRiskClassfyType(String fiveLevel) {
//        String level = fiveLevel==null?"":fiveLevel;
//        switch(level) {
//        case "正常":
//            return RiskClassfyType.NORMAL_ONE;
//        case "关注":
//            return RiskClassfyType.FOCUS_ONE;
//        case "可疑":
//            return RiskClassfyType.SUSPICIOUS;
//        case "次级":
//            return RiskClassfyType.SECONDARY;
//        case "损失":
//            return RiskClassfyType.LOSS;
//        default :
//            return RiskClassfyType.NONE;
//        }
//    }
//    
//    /**
//     * 获取担保方式
//     * @param guarType
//     * @return
//     */
//    /*private GuaranteeType getGuaranteeType(String guarType) {
//        String type = guarType==null?"":guarType;
//        switch (type) {
//        case "免担保":
//            return GuaranteeType.CREDIT;
//        case "组合(不含保证)担保":
//            return GuaranteeType.GUAR;
//        case "抵押担保":
//            return GuaranteeType.MORTGAGE;
//        case "质押担保":
//            return GuaranteeType.PLEDGE;
//        default :
//            return GuaranteeType.OTHER;
//        }
//    }*/
//    
//    
//    private GuaranteeType getGuaranteeType(String guarType) {
//    	if  (StringUtils.isEmpty(guarType)) return GuaranteeType.OTHER;
//    	
//        if ( guarType.equals("信用/免担保") ) {
//        	return GuaranteeType.CREDIT;
//        }else if ( guarType.equals("组合（不含保证）担保") || guarType.equals("组合（含保证）担保") ) {
//        	return GuaranteeType.GUAR;
//        }else if ( guarType.equals("抵押担保") ) {
//        	return GuaranteeType.MORTGAGE;
//        }else if ( guarType.equals("质押担保") ) {
//        	return GuaranteeType.PLEDGE;
//        } else if ( guarType.equals("保证")) {
//            return GuaranteeType.ENSURE;
//        } else
//        	return GuaranteeType.OTHER;
//    }
//    
//    
//    private LoanStatus getLoanStatus(String loanStatus) {
//    	if  (StringUtils.isEmpty(loanStatus)) {
//    		return LoanStatus.OTHER;
//    	}else {
//    		switch (loanStatus) {
//			case "正常":
//				return LoanStatus.NORMAL;
//			case "结清":
//				return LoanStatus.CLOSE_OVER;
//			default :
//				return 	LoanStatus.OTHER;
//			}
//    	}
//    	
//    }
//
//
//    @Override
//    public RunRuleResultVO lmtAdjustAccessRule(String bizSerno) throws Exception {
//        logger.info("开始为lmtAdjustAccessRule准备数据，bizSerno："+bizSerno);
//        RunRuleResultVO runRuleResultVO = new RunRuleResultVO();
//        runRuleResultVO.setIsPass(false);//先默认不通过
//        boolean reject = false;
//        LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//        LmtAdjustApp updateBean = new LmtAdjustApp();
//        updateBean.setAdjSerno(bizSerno);//提额申请流水号
//        String lmtSerno = null;//授信申请流水号
//        try {
//            /**************数据准备 start**************/
//            RuleArgsEntity ruleArgsEntity = new RuleArgsEntity();
//            lmtAdjustApp.setAdjSerno(bizSerno);//提额申请流水号
//            lmtAdjustApp = lmtAdjustAppDao.queryLmtAdjustAppByPk(lmtAdjustApp);
//            if ( lmtAdjustApp == null )
//                throw new PauseException("提额申请流水号:" + bizSerno +  ",查询额度调整申请表信息为空!");
//            if( StringUtils.isEmpty(lmtAdjustApp.getOuterAuthSerno()))
//                throw new PauseException("外部授权流水号为空,额度测算的额度调整申请信息为:" + JSON.toJSONString(lmtAdjustApp));
//            lmtSerno = lmtAdjustApp.getLmtSerno();
//            //查询最新的产品配置
//            PrdInfoVO prdInfoVo = new PrdInfoVO();
//            prdInfoVo.setPrdCode(lmtAdjustApp.getPrdCode());
//            prdInfoVo = prdInfoService.queryLastPrdInfo(prdInfoVo);
//            if ( prdInfoVo == null )
//                throw new PauseException("产品代码:" + lmtAdjustApp.getPrdCode() +  ",查询产品信息为空!");
//            List<TaxPaymentEnum> enums = new ArrayList<>();
//            enums.add(TaxPaymentEnum.INSTEAD_TAX_PAYMENT_UNIT);
//            enums.add(TaxPaymentEnum.PRIVATE_BUSINESS);
//            enums.add(TaxPaymentEnum.PAYING_TAXES);
//            enums.add(TaxPaymentEnum.ILLEGAL_BREAK_RULE);
//            TaxBaseEntity tax = cusTaxBaseService.getExecuteTaxRuleInfo(enums, lmtAdjustApp.getOuterAuthSerno(), lmtAdjustApp.getCertCode(), lmtAdjustApp.getLegalOrgCode());
//            if ( tax == null )
//                throw new PauseException("外部授权流水号:" + lmtAdjustApp.getOuterAuthSerno() +  ",查询客户税务信息为空!");
//            CtrLoanContVO ctrLoanCont = new CtrLoanContVO();
//            ctrLoanCont.setSerno(lmtSerno);
//            ctrLoanCont = ctrLoanContService.queryFirstCtrLoanCont(ctrLoanCont);
//            CusInfoEntity cusInfo = new CusInfoEntity();
//            if ( null != ctrLoanCont )
//                cusInfo.setContractEndDate(ctrLoanCont.getLoanEndDate());
//
//            ruleArgsEntity.setCusInfo(cusInfo);
//            ruleArgsEntity.setTax(tax);
//            //设置禁入行业
//            String industry = bizParamCfgService.bizParamCfgEnumFn(lmtAdjustApp.getLegalOrgCode(), BizParamCfgEnum.FORBID_INDUS);
//            BizConfigParam bizConfigParam = new BizConfigParam();
//            if (!StringUtil.isEmpty(industry)) {
//                String[] outIndustry = industry.split("\\,");
//                List<String> keepOutIndustry = Arrays.asList(outIndustry);
//                bizConfigParam.setKeepOutIndustry(keepOutIndustry);
//            }
//            ruleArgsEntity.setCfgParam(bizConfigParam);//设置业务参数进入行业
//            /**************数据准备 end**************/
//            //2.执行规则
//            //一般跑两次，一次省的规则，一次当前产品的规则
//            String prdId = prdInfoVo.getPrdId();
//            
//            List<SRuleCollVO> listRuleColl = new ArrayList<>();
//            SRuleCollVO sRuleCollVo = new SRuleCollVO();
//            sRuleCollVo.setRuleCollType(RuleTypeConstant.INCREASE_ADMIT);//提额准入规则
//            sRuleCollVo = sRuleCollService.queryProvinceRuleCollByType(sRuleCollVo);
//            if(Objects.nonNull(sRuleCollVo)) {
//                listRuleColl.add(sRuleCollVo);
//            } else {
//                logger.error(bizSerno+"获取省信贷提额准入规则为空！");
//            }
//            
//            //获取产品配置规则
//            PrdRuleRelVO prdRuleRelVO = prdInfoService.queryPrdRuleRel(prdId, RuleTypeConstant.INCREASE_ADMIT);
//            if(Objects.nonNull(prdRuleRelVO)) {
//                SRuleCollVO sRuleCollVo2 = new SRuleCollVO();
//                sRuleCollVo2.setRuleCollId(prdRuleRelVO.getRuleCollId());
//                sRuleCollVo2.setRuleCollDesc(prdRuleRelVO.getRuleCollDesc());
//                listRuleColl.add(sRuleCollVo2);
//            } else {
//                logger.error(bizSerno+"获取产品["+prdInfoVo.getPrdCode()+"-"+prdInfoVo.getPrdName()+"]配置提额准入规则为空！prdId="+prdId);
//                throw new Exception(bizSerno+"获取产品["+prdInfoVo.getPrdCode()+"-"+prdInfoVo.getPrdName()+"]配置提额准入规则为空！prdId="+prdId);
//            }
//
//            //所有的规则集，执行通过结果
//            List<Boolean> ruleResults = new ArrayList<>(listRuleColl.size());
//            logger.info(bizSerno + "执行的规则集" + listRuleColl);
//            boolean flag;
//
//            for(SRuleCollVO ruleCollVO : listRuleColl) {
//                String ruleCollId = ruleCollVO.getRuleCollId();//规则集ID
//                String ruleCollDesc = ruleCollId + "-" + ruleCollVO.getRuleCollDesc();//规则集描述
//                RuleResultEntity ruleResultEntity = ruleCallService.executeRule(bizSerno, prdId, ruleCollId, ruleArgsEntity);
//                if(Objects.nonNull(ruleResultEntity)){
//                    flag = RuleEntity.PASS.equals(ruleResultEntity.getExecuteReslut());
//
//                    ruleResults.add(flag);
//                    logger.info("业务流水号:" + bizSerno + ";执行规则[" + ruleCollDesc + "]是否通过结果为: " + flag);
//                }
//            }
//            for(Boolean b : ruleResults){
//                runRuleResultVO.setIsPass(b);
//                if(!b) {
//                    reject = true;
//                    throw new TerminateException(FlowExceptionType.EVENT, "执行提额申请准入结果为不通过，业务流程结束！bizSerno=" + bizSerno);
//                }
//            }
//
//        } catch (Exception e) {
//            logger.error("额度调整准入规则出现异常！", e);
//            throw new PauseException(e.getMessage());
//        } finally {
//            if(reject) {
//                updateBean.setApproveStatus(BaseConstant.APPR_STATUS_998);
//                updateBean.setAdjStatus(LimitConstant.ADJ_STATUS_99);
//                updateBean.setRejectReason(LimitConstant.REJECT_REASON_01);
//                updateBean.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//                logger.error("额度调整命中准入规则，审批拒绝。updateBean=" + JSONObject.toJSONString(updateBean));
//                lmtAdjustAppDao.updateLmtAdjustAppByPk(updateBean);
//                
//                //检查合同是否已签订
//                boolean signFlag = ctrLoanContService.getContSignedCountBySerno(lmtSerno) > 0;
//                logger.info("根据授信申请流水号["+lmtSerno+"]检查合同是否已签订，signFlag=" + signFlag);
//                
//                //修改lmt_show_info
//                LmtShowInfo lmtShowInfo = new LmtShowInfo();
//                lmtShowInfo.setLmtSerno(lmtSerno);//授信申请流水号
//                if(!signFlag) {
//                    //未曾激活额度
//                    //查询第一次申请额度是否审批通过
//                    LmtIndivApp lmtIndivApp = new LmtIndivApp();
//                    lmtIndivApp.setLmtSerno(lmtSerno);//授信申请流水号
//                    lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//                    if(BaseConstant.APPR_STATUS_998.equals(lmtIndivApp.getApproveStatus())) {
//                        lmtShowInfo.setLmtStatus(PreCreStatus.APPLY_FAIL.getCode());//申请失败
//                    } else {
//                        lmtShowInfo.setLmtStatus(PreCreStatus.ACTIVE_WAIT.getCode());//待激活
//                    }
//                }
//                lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
//                logger.info("修改lmt_show_info！lmtShowInfo=" + JSONObject.toJSONString(lmtShowInfo));
//                lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
//                
//                //提额申请准入拒绝，插入客户提示消息表
//                CusPromptMsgVO cusPromptMsgVo = new CusPromptMsgVO();
//                cusPromptMsgVo.setBizSerno(lmtAdjustApp.getAdjSerno());//业务流水号
//                cusPromptMsgVo.setMsgType(MessageType.LMT_ADJUST_ACCESS_REJECT);//消息类型
//                cusPromptMsgVo.setCusId(lmtAdjustApp.getCusId());//客户号
//                cusPromptMsgVo.setCusName(lmtAdjustApp.getCusName());//客户名称
//                cusPromptMsgVo.setCertType(lmtAdjustApp.getCertType());//证件类型
//                cusPromptMsgVo.setCertCode(lmtAdjustApp.getCertCode());//证件号码
//                cusPromptMsgVo.setMsgContent("尊敬的客户，您的纳税信用信息不满足我行的贷款准入条件，提额申请未通过。若有疑问，请联系96138");//消息内容
//                cusPromptMsgVo.setQueryTimes(0);//查询次数
//                cusPromptMsgVo.setLegalOrgCode(lmtAdjustApp.getLegalOrgCode());//法人机构号
//                cusPromptMsgVo.setCreateTime(TimeUtil.getCurrentDateTime());//创建时间
//                cusPromptMsgVo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
//                cusPromptMsgService.insertCusPromptMsg(cusPromptMsgVo);
//            }
//        }
//        return runRuleResultVO;
//    }
//
//
//    @Override
//    public BigDecimal lmtAdjustCalcLimit(String bizSerno) throws Exception {
//        logger.info("开始为lmtAdjustCalcLimit准备数据，bizSerno："+bizSerno);
//        BigDecimal resultAmt = BigDecimal.ZERO;//默认额度
//        LmtAdjustApp updateBean = new LmtAdjustApp();
//        updateBean.setAdjSerno(bizSerno);//提额申请流水号
//        try {
//            /**************数据准备 start**************/
//            //TODO 准备额度测算的数据
//            RuleArgsEntity ruleArgsEntity = new RuleArgsEntity();
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            lmtAdjustApp.setAdjSerno(bizSerno);//提额申请流水号
//            lmtAdjustApp = lmtAdjustAppDao.queryLmtAdjustAppByPk(lmtAdjustApp);
//            logger.info("额度测算的额度调整申请信息:" + JSON.toJSONString(lmtAdjustApp));
//            if(null == lmtAdjustApp)
//                throw new Exception("额度测算的额度调整申请信息为空!");
//            if( StringUtils.isEmpty(lmtAdjustApp.getOuterAuthSerno()))
//                throw new Exception("外部授权流水号为空,额度测算的额度调整申请信息为:" + JSON.toJSONString(lmtAdjustApp));
//            /**************数据准备 end**************/
//            
//            //查询最新的产品配置
//            PrdInfoVO prdInfoVo = new PrdInfoVO();
//            prdInfoVo.setPrdCode(lmtAdjustApp.getPrdCode());
//            prdInfoVo = prdInfoService.queryLastPrdInfo(prdInfoVo);
//            //查询客户税务信息
//            List<TaxPaymentEnum> enums = new ArrayList<>();
//            enums.add(TaxPaymentEnum.INSTEAD_TAX_PAYMENT_UNIT);
//            enums.add(TaxPaymentEnum.PAYING_TAXES);
//            TaxBaseEntity tax = cusTaxBaseService.getExecuteTaxRuleInfo(enums, lmtAdjustApp.getOuterAuthSerno(), lmtAdjustApp.getCertCode(), lmtAdjustApp.getLegalOrgCode());
//
//            ruleArgsEntity.setTax(tax);
//
//            //秒贷申请信息
//            LmtIndivApp lmtIndivApp = new LmtIndivApp();
//            lmtIndivApp.setLmtSerno(lmtAdjustApp.getLmtSerno());
//            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//            if(null == lmtIndivApp)
//                throw new Exception("查询秒贷申请信息为空,授信申请流水号:" + lmtAdjustApp.getLmtSerno());
//            CusPrelistRiskInfoVO cusPrelistRiskInfoVo = new CusPrelistRiskInfoVO();
//            cusPrelistRiskInfoVo.setPreSerno(lmtIndivApp.getPreSerno());
//            cusPrelistRiskInfoVo = cusPrelistRiskInfoService.queryByCondition(cusPrelistRiskInfoVo);
//            //客户行内贷款信息
//            BankInnerLoanEntity innerLoan = new BankInnerLoanEntity();
//            //客户系统内（指得是行内系统贷款）所有机构未结清信用及保证产品的授信总金额（含本次申请额度）不得超过N万元（N=100万）
//            innerLoan.setTotalCreditGuarAmt(cusPrelistRiskInfoVo.getBankTotalLmtamt());
//            ruleArgsEntity.setInnerLoan(innerLoan);
//            ApplyEntity apply = new ApplyEntity();
//            PrdInfoEntity prdInfo = new PrdInfoEntity();
//            prdInfo.setCrdAprvMaxAmt(prdInfoVo.getCrdAprvMaxAmt()); //产品最大值
//            prdInfo.setCrdAprvMinAmt(prdInfoVo.getCrdAprvMinAmt()); //产品最小值
//
//            apply.setPrdInfo(prdInfo);
//            ruleArgsEntity.setApply(apply);
//            //获取征信信息
//            CusRptRecordVO cusRptRecordVO = new CusRptRecordVO();
//            cusRptRecordVO.setCertCode(lmtIndivApp.getCertCode());
//            cusRptRecordVO.setCertType(lmtIndivApp.getCertType());
//            cusRptRecordVO.setQueryMOrg(lmtIndivApp.getLegalOrgCode());
//
//            CusRptResultVO cusRptResultVO = cusRptCdtAppService.queryRptForPSP(cusRptRecordVO);
//            if (Objects.isNull(cusRptResultVO)
//                    || Objects.isNull(cusRptResultVO.getCusRptCdtAppVo())
//                    || StringUtil.isEmpty(cusRptResultVO.getCusRptCdtAppVo().getReportno())) {
//                throw new PauseException("查询征信信息为空！参数：" + JSONObject.toJSONString(cusRptRecordVO));
//            }
//            PersonalCreditEntity credit = new PersonalCreditEntity();
//            CusRptPromptInfoVO promptInfoVO = cusRptResultVO.getCusRptPromptInfoVo();
//            if ( null != promptInfoVO) {
//                BigDecimal LoanCardUsedAvg6 = promptInfoVO.getUNDLoanCardUsedAvg6();
//                if ( null == LoanCardUsedAvg6)
//                    LoanCardUsedAvg6 = BigDecimal.ZERO;
//                BigDecimal sLoanCardUsedAvg6 = promptInfoVO.getUNDSLoanCardUsedAvg6();
//                if ( null == sLoanCardUsedAvg6 )
//                    sLoanCardUsedAvg6 = BigDecimal.ZERO;
//                BigDecimal userAvg6 = LoanCardUsedAvg6.add(sLoanCardUsedAvg6);
//                credit.setSixAvgUsedAmt(userAvg6);//最近6个月平均使用额度
//            }
//            List<CusRptLoanInfoVO> loanInfos = cusRptResultVO.getCusRptLoanInfoVo();
//            List<CreditCardEntity> cards = null;
//            if(null != loanInfos && loanInfos.size() > 0) {
//                cards = new ArrayList<>();
//                for(CusRptLoanInfoVO infoVO : loanInfos) {
//                    CreditCardEntity creditCardEntity = new CreditCardEntity();
//                    creditCardEntity.setStartYearMonth(infoVO.getRepay24stateStart());//还款的开始日期
//                    creditCardEntity.setEndYearMonth(infoVO.getRepay24stateEnd());//还款的结束日期
//                    if (!StringUtil.isEmpty(infoVO.getLoanState()))
//                        creditCardEntity.setLoanStatus(getLoanStatus(infoVO.getLoanState()));//贷款状态
//                    else if (!StringUtil.isEmpty(infoVO.getLoanStateDetail()))
//                        creditCardEntity.setLoanStatus(getLoanStatus(infoVO.getLoanStateDetail()));//贷款状态
//                    else
//                        creditCardEntity.setLoanStatus(LoanStatus.OTHER);
//
//                    creditCardEntity.setCardNo(infoVO.getLoanId());//贷款id
//                    creditCardEntity.setLoanBalAmt(infoVO.getLoanBalance());//贷款余额
//                    creditCardEntity.setCardType(CreditCardType.LOAN_CARD);
//                    creditCardEntity.setLoanType(getLoanType(infoVO.getLoanPrd()));//贷款类型
//                    creditCardEntity.setTotalAmt(infoVO.getLoanAmount());//总额
//                    creditCardEntity.setBankNo(infoVO.getLoanOrg());//行号
//                    creditCardEntity.setRiskClassfy(getRiskClassfyType(infoVO.getFiveLevel()));//风险分类
//                    creditCardEntity.setGuarType(getGuaranteeType(infoVO.getGuarType()));//担保方式
//                    creditCardEntity.setCurrMonthUsedAmt((infoVO.getsPaymentAmt()));//当前月应还金额
//                    creditCardEntity.setLastRepayNum(infoVO.getRepaymentCyc());//剩余还款期数
//
//                    cards.add(creditCardEntity);
//                }
//            }
//            credit.setCards(cards);
//
//            ruleArgsEntity.setCredit(credit);
//            //业务参数信息
//            BizConfigParam cfgParam = new BizConfigParam();
//            //省级业务参数配置 授信总限额（万）
//            String crdLmtAmtStr = bizParamCfgService.bizParamCfgEnumFn("00001", BizParamCfgEnum.CRD_LMT_AMT);
//            BigDecimal crdLmtAmt = null;
//            if ( !StringUtils.isEmpty(crdLmtAmtStr) )
//                crdLmtAmt = new BigDecimal(crdLmtAmtStr);
//            //法人机构业务参数配置 授信总限额（万）
//            String legalCrdLmtAmtStr = bizParamCfgService.bizParamCfgEnumFn(lmtIndivApp.getLegalOrgCode(), BizParamCfgEnum.CRD_LMT_AMT);
//            BigDecimal legalCrdLmtAmt = null;
//            if ( !StringUtils.isEmpty(legalCrdLmtAmtStr) )
//                legalCrdLmtAmt = new BigDecimal(legalCrdLmtAmtStr);
//            if ( crdLmtAmt == null && legalCrdLmtAmt != null )
//                crdLmtAmt = legalCrdLmtAmt;
//            else if ( crdLmtAmt != null && legalCrdLmtAmt != null)
//                crdLmtAmt = crdLmtAmt.min(legalCrdLmtAmt);
//            cfgParam.setCrdLmtAmt(crdLmtAmt);
//
//            ruleArgsEntity.setCfgParam(cfgParam);
//            IncreaseInfoEntity param = new IncreaseInfoEntity();
//            //提额系数
//            BigDecimal increaseCoeffic = null;
//            String increaseCoefficStr = bizParamCfgService.bizParamCfgEnumFn(lmtAdjustApp.getLegalOrgCode(), BizParamCfgEnum.AMT_COEFFICIENT);
//            if ( StringUtils.isNotEmpty(increaseCoefficStr))
//                increaseCoeffic = new BigDecimal(increaseCoefficStr);
//            if ( increaseCoeffic == null ){
//                increaseCoefficStr = bizParamCfgService.bizParamCfgEnumFn("00001", BizParamCfgEnum.AMT_COEFFICIENT);
//                if ( StringUtils.isNotEmpty(increaseCoefficStr))
//                    increaseCoeffic = new BigDecimal(increaseCoefficStr);
//            }
//            List<String> typeCodes = null;
//            if ( null != tax.getPayTaxUnits() && tax.getPayTaxUnits().size() > 0 ) {
//                typeCodes = new ArrayList<>(tax.getPayTaxUnits().size());
//                for (PayTaxUnitEntity payTaxUnit: tax.getPayTaxUnits()) {
//                    typeCodes.add(payTaxUnit.getTaxType());
//                }
//            }
//            //注册单位系数
//            Map<String, BigDecimal> regisTypeCoeffic = coeffCfgService.queryCoffByLegalTypes(typeCodes, lmtAdjustApp.getLegalOrgCode());
//            param.setRegisTypeCoeffic(regisTypeCoeffic);
//            param.setIncreaseCoeffic(increaseCoeffic);
//
//            tax.setParam(param);
//            //秒贷测算额度
//            BigDecimal secondLoanAmount = BigDecimal.ZERO;
//            CusInfoEntity cusInfo = new CusInfoEntity();
//            LmtPrdCont lmtPrdCont = new LmtPrdCont();
//            lmtPrdCont.setLmtContNo(lmtAdjustApp.getLmtContNo());
//            lmtPrdCont = lmtPrdContDao.queryByPk(lmtPrdCont);
//            if ( null != lmtPrdCont) {
//                secondLoanAmount = lmtPrdCont.getLmtAmt();
//            }else
//                secondLoanAmount = lmtIndivApp.getApproveAmt();
//            cusInfo.setSecondLoanAmount(secondLoanAmount);
//            ruleArgsEntity.setCusInfo(cusInfo);
//            String prdId = prdInfoVo.getPrdId();//产品ID
//            
//            //获取产品配置规则
//            PrdRuleRelVO prdRuleRelVO = prdInfoService.queryPrdRuleRel(prdId, RuleTypeConstant.INCREASE_CREDIT_CALC);
//            
//            BigDecimal calcAmt = ruleCallService.calcLimit(bizSerno, prdId, prdRuleRelVO.getRuleCollId(), ruleArgsEntity);
//            logger.info(bizSerno+"测算额度为：" + calcAmt);
//            calcAmt = Objects.isNull(calcAmt)?BigDecimal.ZERO:calcAmt;
//            updateBean.setCalcLmt(calcAmt);//测算出来的额度
//            BigDecimal adjBasicLmt = lmtAdjustApp.getAdjBasicLmt();
//            resultAmt = calcAmt.subtract(adjBasicLmt);
//            //提额最小额度
//            BigDecimal increaseMinAmt = null;
//            String increaseMinAmtStr = bizParamCfgService.bizParamCfgEnumFn(lmtAdjustApp.getLegalOrgCode(), BizParamCfgEnum.AMT_LMT_MIN);
//            logger.info("法人机构提额最小额度:" + increaseMinAmtStr);
//            if ( StringUtils.isNotEmpty(increaseMinAmtStr))
//                increaseMinAmt = new BigDecimal(increaseMinAmtStr);
//            if ( increaseMinAmt == null ){
//                increaseMinAmtStr = bizParamCfgService.bizParamCfgEnumFn("00001", BizParamCfgEnum.AMT_LMT_MIN);
//                logger.info("省级机构提额最小额度:" + increaseMinAmtStr);
//                if ( StringUtils.isNotEmpty(increaseMinAmtStr))
//                    increaseMinAmt = new BigDecimal(increaseMinAmtStr);
//            }
//            if ( null == increaseMinAmt)
//                increaseMinAmt = BigDecimal.ZERO;
//            //提额后授信额度-原秒贷额度＜N元（业务参数中提额额度最小值(元)），提额失败
//            if ( resultAmt.compareTo(increaseMinAmt) < 0)
//                resultAmt = BigDecimal.ZERO;
//
//            //如果是负数，赋值0
//            resultAmt = resultAmt.signum()==-1?BigDecimal.ZERO:resultAmt;
//        } catch (Exception e) {
//            logger.error("额度调整计算额度出现异常！", e);
//            throw new PauseException(e.getMessage());
//        } finally {
//            updateBean.setAdjResultLmt(resultAmt);//调整结果额度
//            updateBean.setLastUpdateTime(TimeUtil.getCurrentDateTime());
//            logger.info("更新额度调整申请表信息，updateBean=" + JSONObject.toJSONString(updateBean));
//            lmtAdjustAppDao.updateLmtAdjustAppByPk(updateBean);
//        }
//        return resultAmt;
//    }
//}
